wasm-demo/demo/ermis-f/python_m/cur/0290

61 lines
2.3 KiB
Plaintext

From: doughellmann at mindspring.com (Doug Hellmann)
Date: Sat, 03 Apr 1999 17:37:29 -0500
Subject: Tkinter problem (threads?)
References: <slrn7g9d5r.clm.robert.vollmert@krikkit.vollmert.home>
Message-ID: <37069828.89C5B08C@mindspring.com>
Content-Length: 2031
X-UID: 290
Robert,
You might want to look into the after_idle method available from the
Tkinter widget classes. It basically registers a function to be called
during the next "idle" period of the event loop. The idle period is
either after or before all normal events have been processed (I don't
know which). I have successfully used this technique in several
applications to do my processing "in the background" while the
interface remains responsive.
The trick is to remember that while your idle function is running, the
interface *won't* update. Only after you return (or call
update_idletasks will it update. The best thing to do is make your idle
function perform only a small piece of your processing.
For instance, in one program I had an idle function that polled several
pipes using select to see if any of them had output. When it found
output, it would read a small buffer, process it, and return. When it
found no output it would return immediately. That way, the interface
was very responsive, since my function didn't hang it up for very long.
I kept my state information (list of pipes, portion of buffer not
processed, etc.) as member variables of my application class. The idle
function was a method of the class, so I could access everything I
needed from the application instance.
Oh, one other thing you need to know is that calling after_idle only
registers the function to be called one time. You will need to have
your function re-register itself if it has more processing to do.
Let me know if you run into trouble, I'd be happy to help.
Doug
Robert Vollmert wrote:
>
> I'm experiencing a problem while writing a simple plotting program
> using Tkinter: I've created a Plot class which, after being
> initialized with a canvas instance, gets new values through an add
> method.
>
> How can I make Tk enter the mainloop (in order to show the plot) and
> still add new values afterwards?
>
> TIA, Robert
>
> --
> Robert Vollmert rvollmert at gmx.net