Adding command to a Tkinter OptionMenu?

怎甘沉沦 提交于 2019-11-29 12:47:42

There is never a need for a direct apply call, which is why is is dreprecated in 2.7 and gone in 3.0. Instead use the *seq syntax. Just combine the two things you did. The following seems to do what you want.

from tkinter import *

def func(value):
    print(value)

root = Tk()
options = ["1", "2", "3"]
var = StringVar()
drop = OptionMenu(root, var, *options, command=func)
drop.place(x=10, y=10)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!