如何解决使用tkinter创建多个组合框
我试图创建多个相互依赖的组合框,然后根据所选组合框的值在应用程序上写一个标签。 因此,从下面的代码中,我想选择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 举报,一经查实,本站将立刻删除。