Tkinter + threads = trouble?

Tim Peters tim.one at home.com
Mon Sep 17 01:45:43 EDT 2001


The basic rule with Tk (and several other GUI systems) is that you can run
them fine with threads, *provided that* all interaction with the GUI is
funneled through a single thread.  You can even write threaded apps that run
fine under IDLE if you follow that rule (and note that, e.g., printing to
sys.stdout counts as "interacting with the GUI" then, since the GUI
component paints the pixels on the screen).

So whichever thread kicks off Tk is the only thread that can ever talk to
Tk, or get called back from it.  For example, structure that thread as an
infinite loop, taking requests for GUI interaction off an instance of the
Queue class.

for-more-info-read-the-tcl/tk-source-code<wink/sigh>-ly y'rs  - tim





More information about the Python-list mailing list