Tkinter GUI Application Development Blueprints, Second Edition - Second Edition
by Bhaskar Chaudhary
Tkinter and thread safety
Tkinter is not thread safe. The Tkinter interpreter is valid only in the thread that runs the main loop. Any calls to widgets must ideally be done from the thread that created the main loop. Invoking widget-specific commands from other threads is possible but is not reliable.
When you call a widget from another thread, the events get queued for the interpreter thread, which executes the command and passes the result back to the calling thread. If the main loop is running but not processing events, it sometimes results in unpredictable exceptions.
In fact, if you find yourself calling a widget from a thread other than the main loop, chances are that you have not separated the visual elements from the underlying data ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access