Timer APIs - Simplified Time-based Events
Timer methods of Window object in call reference
The Timer API calls are new in PySimpleGUI 5. They help you manage timers that are more accurate than using the timeout
parameter in Window.read()
.
Do Not Use Sleeps In Your Event Loop...
Instead of sleeping, you can request that an event be generated after some period of time. If you need to "Sleep for 3 seconds" as part of some operation, instead schedule a timer for 3 seconds. Your window.read
call will return a value of sg.TIMER_KEY
or sg.EVENT_TIMER
(they are aliases and thus have the same value).
Timer API Calls
These are the API calls that you'll use to manage timers:
window.timer_start
starts a timer
window.timer_stop
stops a single timer
window.timer_stop_all
stops all timers
window.timer_get_active_timers
returns a list of active timer IDs
Example - start a 3 second timer that does not repeat:
When this timer expires, you'll get an event sg.EVENT_TIMER
. If you want to specify your own key to be returned, then use the key
parameter: