PyGTK Timeout - PyGTK

What is PyGTK Timeout?

The gobject module of the PyGTK API has a beneficial function to make a timeout function that will be called occasionally.

The second argument is the callback function you wish to have called after every millisecond which is the value of the first argument – interval. Additional arguments may be passed to the callback as function data.

The return value of this function is source_id. Using it, the callback function is stopped from calling.

The callback function needs to return True in order to keep repeating. So, it can be stopped by returning False.

Two buttons and two labels are put on a toplevel window in the following program. One label displays an incrementing number. The btn1 calls on_clickwhich sets the timeout function with an interval of 1000 ms (1 second).

The timeout function is named as counter(). It increments the number on a label after every 1 second.

The Callback on the second button removes the timeout function.


Example
The resulting is the complete code for the Timeout example –

When performed, the window displays two buttons at the bottom. The number on the label will increment occasionally when the Start button is clicked on and it will stop incrementing when the Stop button is clicked on.

Observe the output –

timeout_demo

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

PyGTK Topics