Tkinter's scheduling mechanism not only provides methods to delay callback executions, but also to cancel them if they have not been executed yet. Consider an operation that may take too much time to complete, so we want to let users to stop it by pressing a button or closing the application.
Canceling scheduled actions
Getting ready
We will take the example from the first recipe and add a Stop button to allow us to cancel the scheduled action.
This button will be enabled only while the action is scheduled, which means that once you click on the left button, the user can wait for 5 seconds, or click on the Stop button to immediately enable it again: