pythonware.com products ::: library ::: search ::: daily Python-URL!

Library

An Introduction to Tkinter

Alarm handlers and other non-event callbacks :::

A Django site.
   

Alarm handlers and other non-event callbacks

Back   Next   

 Alarm handlers and other non-event callbacks

 after

after(delay_ms, callback, args...). Register an alarm callback that is called after the given number of milliseconds (Tkinter only guarantees that the callback will not be called earlier than that; if the system is busy, the actual delay may be much longer). The callback is only called once for each call to after. To keep calling the callback, you need to reregister the callback inside itself:

    class App:
        def __init__(self, master):
            self.master = master
            self.poll() # start polling
    
        def poll(self):
            ...
            self.master.after(100, self.poll)

You can provide one or more arguments which are passed to the callback. This method returns an alarm id which can be used with after_cancel to cancel the callback.

  after_cancel

after_cancel(id). Cancels the given alarm callback.

 after

after(delay_ms). Wait for the given number of milliseconds. Note that in the current version, this also blocks the event loop. In practice, this means that you might as well do:

    time.sleep(delay_ms*0.001)

  after_idle

after_idle(callback, args...). Register an idle callback which is called when the system is idle (that is, when there are no more events to process in the mainloop). The callback is only called once for each call to after_idle.

Back   Next