from tkinter import *
from tkinter.ttk import *
window=Tk()
OPTIONS = [
"Component",
"abc",
"efg",
]
lbl_6 = Label(window,text="Please select options").place(x=10,y=130)
variable = StringVar(window)
variable.set(OPTIONS[0]) # default value
w = OptionMenu(window, variable, *OPTIONS).place(x=275,y=130)
variable.trace("w", callback)
window.resizable(0, 0)
window.mainloop()
def callback(*args):
if variable.get() == "efg":
OPTIONS = [
"Location",
"ijk",
"lmn",
]
variable1 = StringVar(window)
variable1.set(OPTIONS[0]) # default value
w1 = OptionMenu(window, variable1, *OPTIONS).place(x=400,y=130)
def callback1(*args):
OPTIONS = [
"Side",
"opq",
"rst",
]
variable2 = StringVar(window)
variable2.set(OPTIONS[0]) # default value
w2 = OptionMenu(window, variable2, *OPTIONS).place(x=525,y=130)
variable1.trace("w", callback1)
此代码的问题是它为第二个和第三个选项生成两个选项菜单,我的意思是说,对于位置和侧面选项,我可以在两个单独的opetion菜单中选择相同的“位置”和“侧面”选项菜单。 另外,如果我第二次在组件选项菜单中选择了abc选项,也请帮助我摆脱第二个和第三个选项中的选项。