EMi*_*iTu 5 python combobox tkinter
我在 Tkinter Python 中遇到了组合框更新的问题。
我有两个组合框:
A带有values =['A','B','C']和 的组合框B我想要的是:
A当在组合框中选择值时A,然后在组合框中B显示值['1','2','3']
B当在组合框中选择值时A,然后在组合框中B显示值['11','12','13']
C当在组合框中选择值时A,然后在组合框中B显示值 s['111','112','113']
目前我的部分代码如下:
def CallHotel(*args):
global ListB
if hotel.get()==ListA[0]
ListB=ListB1
if hotel.get()==ListA[1]
ListB=ListB2
if hotel.get()==ListA[2]
ListB=ListB3
ListA=['A','B','C']
ListB1=['1','2','3']
ListB2=['11','12','13']
ListB3=['111','112','113']
ListB=ListB1
hotel = StringVar()
hotel.set('SBT')
comboboxA=ttk.Combobox(win0,textvariable=hotel,values=ListA,width=8)
comboboxA.bind("<<ComboboxSelected>>",CallHotel)
comboboxA.pack(side='left')
stp = StringVar()
stp.set('STP')
comboboxB=ttk.Combobox(win0,textvariable=stp,values=ListB,width=15)
comboboxB.pack(side='left')
Run Code Online (Sandbox Code Playgroud)
实际上你不需要全局变量ListB。并且您需要comboboxB.config(values=...)在末尾添加CallHotel()来设置以下选项comboboxB:
def CallHotel(*args):
sel = hotel.get()
if sel == ListA[0]:
ListB = ListB1
elif sel == ListA[1]:
ListB = ListB2
elif sel == ListA[2]:
ListB = ListB3
comboboxB.config(values=ListB)
Run Code Online (Sandbox Code Playgroud)
comboboxB并直接将的初始值更改为ListB1:
comboboxB=ttk.Combobox(win0,textvariable=stp,values=ListB1,width=15)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7834 次 |
| 最近记录: |