当在选项菜单中选择一个选项时,我试图更改按钮状态,但没有任何变化。谁能告诉我我做错了什么?
from tkinter import *
def setLabel():
changed.set("Active")
def changeState():
pick = choose.get()
if (pick == "op2"):
button['state'] = button.ACTIVE
button.config(text = "ACTIVE")
else:
button['state'] = app.DISABLED
button.config(text = "Disabled")
app = Tk()
app.resizable(40,40)
choose = StringVar()
choose.set("op1")
options = OptionMenu(app, choose, "op1", "op2")
options.pack()
button = Button(app, text = "Disabled", state = DISABLED, command = setLabel)
button.pack()
changed = StringVar()
label = Label(app, textvariable = changed, font = ("helvetica", 10))
label.pack()
app.mainloop()