Skip to content Skip to sidebar Skip to footer

Is Tkinter's `after` Method Thread-safe?

Since tkinter isn't thread-safe, I often see people use the after method to queue some code for execution in the main thread. Here's an example: import tkinter as tk from threading

Solution 1:

after is thread-safe because it is implemented in terms of call which is generally thread-safe according to the CPython source code if CPython and Tcl were built with thread support (the most common case). This means quite a large footprint of tkinter methods are thread-safe, but not all (particularly eval).

If you call after (or call) from some other CPython thread, it will actually send a thread-safe message to the main thread (with the Tcl interpreter) to actually interact with the Tcl API and run the command in the main thread.


Post a Comment for "Is Tkinter's `after` Method Thread-safe?"