The last stop on our widget tour is perhaps the most unique. tkinter also comes with a handful of tools that have to do with the event-driven programming model, not graphics displayed on a computer screen.
Some GUI applications need to perform background activities periodically. For example, to “blink” a widget’s appearance, we’d like to register a callback handler to be invoked at regular time intervals. Similarly, it’s not a good idea to let a long-running file operation block other activity in a GUI; if the event loop could be forced to update periodically, the GUI could remain responsive. tkinter comes with tools for both scheduling such delayed actions and forcing screen updates:
milliseconds, function, *args
This tool schedules the function to be called once by the
GUI’s event processing system after a number of milliseconds.
This form of the call does not pause the program—the callback
function is scheduled to be run later from the normal tkinter
event loop, but the calling program continues normally, and the
GUI remains active while the function call is pending. As also
discussed in Chapter 5, unlike
widget.after events are dispatched in
the main GUI thread and so can freely update the GUI.
function event handler
argument can be any callable Python object: a function, bound
method, lambda and so on. The
milliseconds timer duration argument is an integer which can be used to specify both ...