Question

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)

This is what I've got so far, i think i would probably need to put it in a loop or something for it to change the values but i don't know how i would do that. I've been trying to do this for a long time now so any help would be amazing. Thank you

Was it helpful?

Solution

I was able to solve this problem by giving commands to the 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)

There probably is a better way of doing it, without using functions, but this does exactly what it is meant to do. I hope this can be useful to anyone who has the same problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top