我在Tkinter Python中遇到了combobox更新的问题。
我有两个comboboxes:
- combobox A,values=['A','B','C']; - combobox B。
我想要的是:
- 当在combobox A中选择值'A'时,在combobox B中显示值['1','2','3']; - 当在combobox A中选择值'B'时,在combobox B中显示值['11','12','13']; - 当在combobox A中选择值'C'时,在combobox B中显示值['111','112','113']。
目前我的代码部分如下:
我有两个comboboxes:
- combobox A,values=['A','B','C']; - combobox B。
我想要的是:
- 当在combobox A中选择值'A'时,在combobox B中显示值['1','2','3']; - 当在combobox A中选择值'B'时,在combobox B中显示值['11','12','13']; - 当在combobox A中选择值'C'时,在combobox B中显示值['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')