Skip to content Skip to sidebar Skip to footer

How To Delete (or De-grid) Tkinter Gui Objects Stored In A List (python)

I'm trying to make a program that creates some random amount of GUI objects in Tkinter and stores them in a list. Here (in the code below) I have a for loop that creates a random a

Solution 1:

You need to store references to each object. Create an empty list and append the reference to the list inside your loop.

self.radioButtons = []
for x inrange(2, randInt):
        self.radioButtons.append(Radiobutton(self, text = "Button", variable = self.RadVar, value = x))
        self.radioButtons[-1].grid(row = x) # layout the most recent one

They won't be garbage collected unless you delete the reference as well.

forbuttoninself.radioButtons:
    button.grid_forget()
delself.radioButtons

Post a Comment for "How To Delete (or De-grid) Tkinter Gui Objects Stored In A List (python)"