Tkinter event loops
kkto at csis.hku.hk
Sun Aug 26 12:40:30 CEST 2001
>>>>> "Mike" == Mike Clarkson <support> writes:
Mike> On Mon, 20 Aug 2001 16:16:16 GMT, Howard Lightstone
Mike> <howard at eegsoftware.com> wrote:
>> How do I provide the same event handling as the mainloop method while
>> still allowing me to "poll" other activities?
>> Do I use the update method or update_idletasks method or ???
Mike> What you need is the (undocumented) createtimerhandler method.
Mike> Look at the source code of _tkinter.c at the
Mike> Tkapp_CreateTimerHandler code, and look at the Tk/Tcl
Mike> documentation for Tcl_CreateTimerHandler, Tcl_DeleteTimerHandler -
Mike> call a procedure at a given time.
If the thing that is being waited for is time, it is much simpler to just
use the after-handler (calling Misc.after). But actually most "polls" are
polling devices, or actually files. In these cases, one should use
Tk.tk.createfilehandler. Look at ManPage.py of the Demo shipped with Python
to see how this is done. One can wait for a file to become readable or
writable, of wait until an exception.
In either case, what one need to know is to invert the logic: instead of
trying to fake the main loop and do your own stuff, one should tell the main
loop that there is something waiting to be done, and then continue with the
On the other hand, if one really need to temporarily deal with a computation
exclusively, one can call update. Update_idletask will only run the window
(and "idle tasks"), do that if this is what you want. This will simulate
one iteration of the event loop.
More information about the Python-list