Correctly creating a list of Tkinter Checkboxes

Viewed 39

I have a bunch of checkboxes created all under the name self.ignore and when I try to write the method call self.ignore.deselect() I want all the checkboxes to deselect but nothing happens to any of them. I realize I've probably improperly structured the checkboxes and am looking for a way to fix this. The way I've gone about this is hacky to get to where I am and am looking for a better solution.

I tried just deleting the label that everything is held in. However, when I recreate the label the checkmarks are saved.

Would the correct method of getting my desired result be creating a class called Checkbox and create a class array of each element? What would that look like?

def print_changes(self):
    self.grid_label = Label(root)
    self.grid_label.grid(row=1, column=0, sticky="nw")

    for order_num in range(len(self.given_orders)):
        self.ignore = Checkbutton(self.grid_label, variable=self.ignore_list[-1], 
                                  command=lambda position=position - 1: self.ignore_trigger(position - 1), 
                                  onvalue='on', offvalue='off')
        self.ignore.grid(row=position + 1, column=2)

def recalculate(self):
    self.ignore.deselect()
    self.grid_label.destroy()
0 Answers
Related