可以使用组合框中的选项(optionmenu,dropdown)在启用/禁用小部件之间切换? 我的意思是,如果选择了一个选项,则启用它...与其他人一起,禁用......
如果是,怎么样?
我试过这样的东西,但它没有用......
op = StringVar(root)
op.set("------")
o0 = OptionMenu(root, op, "opt1", "opt2", "opt3","opt4")
if op.get() is "opt1":
e_state = 'ENABLED'
else:
e_state = 'DISABLED'
en9 = Entry(root, width = 30, background = 'white', textvariable = seccion, state=e_state)
答案 0 :(得分:2)
是的,这是可能的。这是一个例子:
import Tkinter as tk
class App(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.op = tk.StringVar(self)
self.op.set("enable")
self.om = tk.OptionMenu(self, self.op, "enable","disable", command=self.OnOption)
self.entry = tk.Entry(self, width=30)
self.om.pack()
self.entry.pack()
def OnOption(self, event):
state = "normal" if self.op.get() == "enable" else "disabled"
self.entry.configure(state=state)
app=App()
app.mainloop()