Chapter 18. Timeouts, IO and Idle Functions

Table of Contents
18.1. Timeouts
18.2. Monitoring IO
18.3. Idle Functions

18.1. Timeouts

You may be wondering how you make GTK do useful work when in mainloop(). Well, you have several options. Using the following function you can create a timeout function that will be called every "interval" milliseconds.
tag = timeout_add(interval, function, ...)

The first argument is the number of milliseconds between calls to your function. The second argument is the callback you wish to have called. Any arguments after the second are passed to the function as data. The return value is an integer "tag" which may be used to stop the timeout by calling:

You may also stop the timeout function by returning zero or FALSE from your callback. Obviously this means if you want your callback to continue to be called, it should return a non-zero value, i.e., TRUE.

Your callback should look something like this:
def timeout_callback(...):

The number of arguments to the callback should match the number of data arguments specified in timeout_add().