def alarmIDList(self, alarms):
carAlarmIDs = []
houseAlarmIDs = []
alarmIDs = []
listDefault = StringVar()
listDefault.set("Select ID")
for alarm in alarms:
alarmIDs.append(alarm.getID())
if isinstance(alarm, CarAlarm):
carAlarmIDs.append(alarm.getID())
elif isinstance(alarm, HouseAlarm):
houseAlarmIDs.append(alarm.getID())
self.alarmType = StringVar()
self.alarmType.set("alarmIDs")
allAlarms = ttk.Radiobutton(self.master, text="All", variable=self.alarmType,
value="alarmIDs").place(x=10, y=30)
carAlarms = ttk.Radiobutton(self.master, text="Car Alarms", variable=self.alarmType,
value="carAlarmIDs").place(x=10, y=50)
houseAlarms = ttk.Radiobutton(self.master, text="House Alarms", variable=self.alarmType,
value="houseAlarmIDs").place(x=10, y=70)
cbox = ttk.Combobox(self.master, textvariable=listDefault,
state='readonly', height=10, width=10)
if self.alarmType.get() == "alarmIDs":
cbox['values'] = alarmIDs
elif self.alarmType.get() == "carAlarmIDs":
cbox['values'] = carAlarmIDs
elif self.alarmType.get() == "houseAlarmIDs":
cbox['values'] = houseAlarmIDs
cbox.place(x = 120, y = 75)
这是我到目前为止所做的,我想我可能需要把它放在一个循环或其他东西来改变价值但我不知道我会怎么做。我一直在努力做这个很长一段时间,所以任何帮助都会很棒。谢谢
答案 0 :(得分:2)
我能够通过向Radiobuttons发出命令来解决这个问题:
def allAlarms():
listDefault.set("Select ID")
cbox['values'] = alarmIDs
def carAlarms():
listDefault.set("Select ID")
cbox['values'] = carAlarmIDs
def houseAlarms():
listDefault.set("Select ID")
cbox['values'] = houseAlarmIDs
allAlarms = ttk.Radiobutton(self.master, text="All", variable=self.alarmType,
value="alarmIDs", command=allAlarms).place(x=10, y=30)
carAlarms = ttk.Radiobutton(self.master, text="Car Alarms", variable=self.alarmType,
value="carAlarmIDs", command=carAlarms).place(x=10, y=50)
houseAlarms = ttk.Radiobutton(self.master, text="House Alarms", variable=self.alarmType,
value="houseAlarmIDs", command=houseAlarms).place(x=10, y=70)
在不使用函数的情况下,可能有更好的方法,但这完全符合它的意图。我希望这对遇到同样问题的人有用。