This is based on answers (1, 2) I gave on stackoverflow. That answer is specific
to the tkinter
toolkit that comes with Python. The principles apply to
other GUI toolkits and languages as well but the terminology used (like
mainloop
and idle task) may be different.