这是在这里发布的答案: Linking two OptionMenu widgets Tkinter
我只是想知道varmenu中的“选择”来自哪里,因为我们没有在command = self.varmenu中传递任何内容
预先感谢
from Tkinter import *
class app:
def __init__(self, root):
win1 = Frame(root)
win1.grid(row=0,column=0)
self.variable = StringVar(win1)
self.variable.set(42)
self.type = OptionMenu(win1, self.variable,
"None", "Clear", "Dark", "Heavy",
command = self.varMenu)
self.type.grid(row=1, column=3, sticky="nsew", padx=1, pady=1)
self.variableunit = StringVar(win1)
self.variableunit.set('mm')
self.unit = OptionMenu(win1,
self.variableunit, "mm", "colour", "shade")
self.unit.grid(row=1, column=5, sticky="nsew", padx=1, pady=1)
def varMenu(self, selection):
if selection == "Heavy":
self.variableunit.set("colour")
self.unit.config(state = DISABLED)
else:
self.variableunit.set("mm")
self.unit.config(state = NORMAL)
root = Tk()
a = app(root)
root.mainloop()