multithreading and Tkinter

Martin v. Loewis martin at v.loewis.de
Thu Mar 21 05:32:07 EST 2002


Arcady Genkin <agenkin at thpoon.com> writes:

> How do I signal the GUI thread that new information for a particular
> object has arrived?  Currently I'm using after() method of the Tkinter
> object to update info for *all* objects every second, but that is
> hardly a good design, since there may be 500 of them, and the new info
> can be arriving once every 15 minutes.
> 
> Any ideas and/or pointers to the documentation (preferably online)
> highly appreciated.

There are different ways to do this. For example, you don't need to
redraw everything in your after() method - just produce a global list
of things to redraw, and have your after method analyse this list.

If you want to delete the need for an after() method altogether, you
could register an after_idle callback. You can do that from a
different thread; Tkinter will call the after_idle callback from the
same thread that runs the mainloop.

Notice that Tkinter currently uses "busy waiting" to cope with
multithreading as well, so an additional after() callback won't hurt
too much.

HTH,
Martin



More information about the Python-list mailing list