Handling idle tasks
There are certain situations where an operation causes a small pause in the execution of the program. It might not even take a second to complete, but it is still noticeable to your users because it introduces a momentary pause in the GUI.
In this recipe, we will discuss how to deal with these scenarios without needing to process the whole task in a separate thread.
Getting ready
We will take the example from the Scheduling actions recipe, but with a timeout of 1 second instead of 5.
How to do it...
When we change the state of the button to DISABLED
, the callback continues its execution, so the state of the button is not actually changed until the system is idle, which means it has to wait for time.sleep()
to complete.
However, we can force Tkinter to update all the pending GUI updates to execute at a specific moment, as shown in the following script:
import time import tkinter as tk class App(tk.Tk): def __init__(self): super().__init__() self.button =...