idle processing
Michael Muller
proteus at cloud9.net
Wed Jun 2 21:19:13 EDT 1999
mlauer at asmoday-atm.rz.uni-frankfurt.de wrote:
>
> Hi,
>
> is there an appropriate place to insert a method
> which does some calculations while the application
> is "idle" (user is not using it or just moving
> the mouse...) - somewhere within the tkinter-
> mainloop ?
>
> --
> Regards & Gruesse from Mickey @ http://www.Vanille.de
> ---------------------------------------------------------
> How could anyone know me - when I don't even know myself ?
The "after" function allows you to execute code after a given period (in
milliseconds) or in idle time:
def someFunction():
" Your code here "
win = SomeWindowClass()
win.after('idle', someFunction)
win.mainloop()
This will cause "someFunction" to be evaluated *once* in the message
loop
when there are no events left in the event queue.
You should be able to "chain" these by adding another "after idle" call
_inside_ the function, thus allowing you to have a function that is
performed
whenver the message queue is idle. This doesn't seem to work quite right
for
me, though. The idle time function ends up blocking the message queue.
It does seem to work if you force a delay between iterations, like so:
win = SomeWindowClass()
def otherFunc():
win.after('idle', someFunc)
def someFunc():
"idle time processing here"
# give the system a second to catch it's breath
win.after(1000, otherFunc)
win.after('idle', someFunc)
=============================================================================
michaelMuller = proteus at cloud9.net | http://www.cloud9.net/~proteus
-----------------------------------------------------------------------------
Mantra for the 60's: Tune in, turn on, drop out
Mantra for the 90's: Turn on, jack in, jerk off
=============================================================================
More information about the Python-list
mailing list