I am using the tkinter GUI package in python and would like to track the progress of a process that loops through a list and does something for each item on the list. I want to track the progress in a label that displays "Item 1 of 100 processed." The label is bound to a String Variable. Here was what I tried originally:
def runLoop(self):
for site in self.sitelist:
#Do stuff
self.x+=1
self.outLabelStrVar="Item " + str(self.x) + " of " + str(len(self.sitelist)) + " processed."
However, this of course did not update in real time, because I never returned to the tkinter window mainloop, as is suggested in threads like this one.
So I updated my code to make the function recursive:
def runLoop(self, item=None):
if item is None:
for site in self.sitelist:
self.after(1,runLoop(site))
else:
self.x+=1
self.outLabelStrVar="Item " + str(self.x) + " of " + str(len(self.sitelist)) + " processed."
Which I thought would return to the main tkinter loop with each iteration of the for loop. But this also doesn't update the output label in real time.
What am I misunderstanding?