我试图创建多个相互依赖的组合框,然后根据所选组合框的值在应用程序上写一个标签。 因此,从下面的代码中,我想选择A1以显示“您选择了A1”。。。我对编码很陌生,可能有更好的方法来编写代码,但我的大脑就是这样思考问题的。谢谢
alpha = [
"A",
"B"
]
alpanum1 = [
"A1",
"A2"
]
alpanum2 = [
"B1",
"B2"
]
from tkinter import *
from tkinter import ttk
roott = Tk()
roott.title('TEST')
roott.geometry("400x400")
def jj2(event):
if j1.get() == alpha[0] and jo2.get() == alpanum1[0]:
Jd = Label(roott, text = "You selected A1", font=('Times', 10, 'italic'), justify='left')
Jd.place(relx=0.05, rely=0.1)
elif j1.get() == alpha[0] and jo2.get() == alpanum1[1]:
Jd = Label(roott, text = "You selected A2", font=('Times', 10, 'italic'), justify='left')
Jd.place(relx=0.05, rely=0.2)
elif j1.get() == alpha[1] and jo2.get() == alpanum2[0]:
Jd = Label(roott, text = "You selected B1", font=('Times', 10, 'italic'), justify='left')
Jd.place(relx=0.05, rely=0.3)
else:
Jd = Label(roott, text = "You selected B2", font=('Times', 10, 'italic'), justify='left')
Jd.place(relx=0.05, rely=0.4)
def jj1(event):
if j1.get() == alpha[0]:
jo2 = ttk.Combobox(roott, value=alpanum1)
jo2.current()
jo2.bind("<<ComboboxSelected>>",jj2)
jo2.place(relx=0.3, rely=0.3)
else:
jo2 = ttk.Combobox(roott, value=alpanum2)
jo2.current()
jo2.bind("<<ComboboxSelected>>", jj2)
jo2.place(relx=0.3, rely=0.3)
j1 = ttk.Combobox(roott, value=alpha)
j1.current(0)
j1.bind("<<ComboboxSelected>>", jj1)
j1.place(relx=0.2, rely=0.2)
roott.mainloop()
目前没有回答
相关问题 更多 >
编程相关推荐