multithreading and Tkinter

Aahz aahzpy at panix.com
Thu Mar 21 10:21:13 EST 2002


In article <uok7s6qqph.fsf at bashful.cdf.toronto.edu>,
Arcady Genkin  <agenkin-dated-1017130182.c426fa at thpoon.com> wrote:
>
>I have a separate thread, responsible for graphical stuff, which
>displays a bunch of objects as "Tkinter.Lablel"s.  Then, I have a
>buhch of separate threads, which collect information about the
>objects over the network, at specified intervals.
>
>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.

The key is to use Queue.Queue() and stuff the queue with both info and
the object to be updated.  You'll still need to use the after() method,
but you'll only do screen updates when info arrives, and you'll only
need to update the changed objects.  For a simplistic example, see my
home page.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"We should forget about small efficiencies, about 97% of the time.
Premature optimization is the root of all evil."  --Knuth



More information about the Python-list mailing list