Using python 3.6.1 and the included tkinter module
I'm trying to have tkinter display a list of 10 cards and their respective expansion packs... I can make it work one time, but I can't seem to make it repeatable with the button.
I want to remove the first set and allow the user to run it again. So I need to identify the widgets and remove them. I used this answer when I was trying to figure out how to identify the label widgets in a specific row. But when I run it, it's not picking up the widgets in the rows. It just returns empty sets for each row.
This first loop is where I setup the labels excerpted from the main class app(Frame) __init__()
method and also the method that should be picking things up to clear them out. I've broken it down further than it needs to be at this point trying to troubleshoot. I think it's a scope issue, I just don't know enough python to get any further in my search without some advice.
from tkinter import *
class App(Frame):
def __init__(self):
super().__init__()
row = 2
for item in range(0, 9):
self.label1 = Label(text="item")
self.label1.grid(row=row, column=0, sticky=W)
self.label2 = Label(text="item")
self.label2.grid(row=row, column=2, sticky=E)
row += 1
button = Button(text="Do the thing!", command=self.replace_labels())
button.grid(row=0, column=1)
def replace_labels(self):
row = 2
for number in range(0, 9):
temp_set = self.grid_slaves(row=number + row)
row += 1
for thing in temp_set:
thing.forget()
def main():
root = Tk()
app = App()
root.mainloop()
if __name__ == '__main__':
main()