I made this program where I am putting labels on a grid without saving them in a variable. I do this because then I can for loop through a list of classes and get the data from each class in and add them to a row. This is a small piece of it:
self.collum = 0
for i in self.gui_resource_list:
Label(text=i.get_name(), relief="groove", width=15).grid(column=self.column, row=0)
Label(text=i.get_buyPrice(), relief="groove", width=15).grid(column=self.column, row=1)
Label(text=i.get_salePrice(), relief="groove", width=15).grid(column=self.column, row=2)
Label(text=i.arrow, relief="groove", width=15).grid(column=self.column,row=3)
self.column += 1
So this will generate a table-like layout. Then there is a button that updates all the values runs that for loop again. So it basically draws the new labels on top of the older ones. This is not good because when you are on the turn 300 there are 300 labels times the all the resource instances in gui_resource
list. A way to fix this is to delete the old labels.
Is there a way to delete an unsaved label? Something like:
delete_grid(column=2,row=3)
And that would delete all of the things in the grid at position 2,3?
You can ask grid to give a list of widgets that it manages. You could then iterate over that list to find out which widget is in each row and column.
For example, if you wanted to be able to modify the text in the widget at a specific row or column, you could do something like this:
Here's an example that will change the text in row 2 column 2 to "hello, world":
You could just as easily delete the widget, though if you're just wanting to refresh a "table-like thing" it's more efficient just to change the data than to delete and recreate all of the widgets.