问题描述
我试图创建多个相互依赖的组合框,然后根据所选组合框的值在应用程序上写一个标签。 因此,从下面的代码中,我想选择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",rely=0.2)
elif j1.get() == alpha[1] and jo2.get() == alpanum2[0]:
Jd = Label(roott,text = "You selected B1",rely=0.3)
else:
Jd = Label(roott,text = "You selected B2",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>>",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()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)