idle processing

Michael Muller proteus at
Thu Jun 3 03:19:13 CEST 1999

mlauer at 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 @
>   ---------------------------------------------------------
>   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)

This will cause "someFunction" to be evaluated *once* in the message
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
whenver the message queue is idle. This doesn't seem to work quite right
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 |
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