Reputation: 1205
I'm working Tkinter GUI for quite sometime. And I was wondering, how after
method actually works on it. My questions are very simple.
after
method is implemented internally in Tkinter ?after
calls threaded ?after
calls in Tkinter ?after
callbacks scheduled ?I did go through a couple of links like this. But couldn't get these informations.
Upvotes: 2
Views: 487
Reputation: 385930
It's really quite simple: Tkinter maintains a queue of work to be done (the event queue), and mainloop
(as well as update
) processes that queue. after
merely adds a timestamped event to the queue. No threads are involved.
Upvotes: 0
Reputation: 8701
after()
calls Tck/Tk's after
command, which registers a callback to be called later by the Tcl/Tk event loop.
after()
calls are not threaded.
One issue is that a blocking or long-running operation may cause something scheduled with after()
to run significantly later than you meant. There are many more possible pros and cons which may be relevant, but you'll need to specify your concerns or use cases...
A callback is registered into Tcl/Tk event loop, which takes care of the scheduling. For details on how that works, see the documentation.
As you may already know, Tkinter uses Tcl/Tk internally.
Taking a look at the code for the after()
method, it appears that Tkinter is just calling the Tcl/Tk after
command.
The documentation for Tcl/Tk's after
command doesn't mention anything about threads. This makes sense given Tcl/Tk's single-threaded event loop design.
So, my conclusion is that Tkinter's after()
method does not use threads, rather it just registers a callback using the internal Tcl/Tk after
command, which will be called at the most appropriate time possible by the Tcl/Tk event loop.
Upvotes: 3