Testing Tkinter code
Testing Tkinter code presents us with a few particular challenges. First, Tkinter handles many callbacks and methods asynchronously, meaning that we can't count on the results of some code to be apparent immediately. Also, testing GUI behaviors often relies on external factors such as window management or visual cues that our tests cannot detect.
We're going to learn some tools and strategies that will help you craft tests for your Tkinter code.
Managing asynchronous code
Whenever you interact with a Tkinter UI—whether it's clicking a button, typing in a field, or raising a window, for example—the response is not executed immediately in-place. Instead, these actions are placed in a to-do list, called an event queue, to be handled later while your code execution continues. While these actions seem instant to users, test code cannot count on a requested action being completed before the next line of code.
To solve this problem, we can use these special widget methods that...