We use this design pattern for projects that actually will need to poll or output something on a regular basis. In this case, we’re indicating we want a timeout=10 in our window.read
call. Also, this will cause the call to return a “timeout key” as the event every 10 milliseconds has passed without some GUI thing happening first. The timeout key is PySimpleGUI.TIMEOUT_KEY which is usually written as sg.TIMEOUT_KEY in normal PySimpleGUI code.
Please be cautious when you are using windows with a timeout. You will rarely need to use a timeout=0 . A zero value is a non-blocking call, so we need not try to abuse this design pattern.
A short note about timers is that this is not a good design for a stopwatch as it can easily drift. This would never pass for a nice solution in a bit of commercial code. For better accuracy, we should always get the actual time from a reputable source, maybe from the operating system. We can use that as what you use to measure and display the time.
To understand it, we will implement a Stopwatch in Python using PySimpleGUI.
- Introduction to PySimpleGUI
- Themes in PySimpleGUI
- Adding Customized Color Theme in PySimpleGUI
- User Input in PySimpleGUI
- PYGLET – Setting Caret Style
- PYGLET – Selecting Word in Caret
- PYGLET – Selecting Point in Caret
- PYGLET – Selecting Paragraph in Caret
- PYGLET – Getting font instances used in Formatted Document
- Python EasyGUI – Yes No Box
- Python EasyGUI – Continue Cancel Box
- Python EasyGUI - Message Box
- Python EasyGUI - Button Box
- Python EasyGUI module - Introduction
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.