Tkinter event based background label updating Tkinter event based background label updating tkinter tkinter

Tkinter event based background label updating


To answer first question -

Why does it work with "self.after" but not with a for loop

The __init__() method of a class is called when an object of that class in created. Now in your case, the class gets created in line -

app = SampleApp()

And in your __init__() , you call - self.mainLoop() .

In your for loop case, all this is running in the main thread. And so it would not return from the self.mainLoop() untill it has completed, since you are not start self.mainLoop() as a separate thread, you are doing that in the same thread. Hence, the control would reach the root.mainloop() line only after self.mainLoop()` has completed and returned the control back.


In case of using after() method, it behaves something like it registers an event to be fired after some amount of time, and immediately returns, it does not wait for that much amount of time and neither for the function to return. Hence the control immediately gets returned and it calls root.mainloop() to show the GUI.