Reputation: 11
What code exactly does mainloop() loop over? I've seen a couple examples where the loop appears to be run over the init function of a window object, but also some where it seems to run over the whole program/no particular object. For what reasons would you set it up one way or the other? And how can you tell what mainloop() is going to execute?
I've read a bunch of Tkinter documentation and StackOverflow questions and (admittedly only skimmed) a couple tutorials, and they all tell me that mainloop() creates and executes an eternal event loop... but there's no detail on what code constitutes the event loop.
Upvotes: 1
Views: 253
Reputation: 184151
The event loop is internal to Tk. It's the code that waits for the user to do something and dispatches those events to the handlers you registered. When it has dispatched one event, it loops back to wait for the next user action. You don't need to do anything with it, but it's what makes the whole system work.
The event loop is found in most (probably virtually all) GUI programming models; it's not just a Tk thing. They don't explain it because it is assumed that you're already familiar with it.
https://en.wikipedia.org/wiki/Event_loop
Upvotes: 1