[Tutor] Tkinter mainloop (was Re: tkFileDialog.Directory)
klappnase at freenet.de
Wed Nov 16 11:33:26 CET 2005
On Wed, 16 Nov 2005 10:55:24 +0100 (MET)
K.Weinert at gmx.net wrote:
> I thought the mainloop() function is something like
> def mainloop():
> e= get_event()
> if e:
> for w in widgets: w.handle(e)
> but apparently it is not.
> It's not bad that the Tkinter windows don't destroy upon an exception,
> since it gives me the option to display an error window, but I feel unsafe
> unless I understand why it does not.
I am not enough of an expert to give you a "complete" answer for that, so anyone
please correct me if I am wrong.
As far as I understand, the mainloop() command just starts a tk shell and Tkinter gives
you an interface to communicate with this tk shell.
In fact Tkinter "translates" any widget command into a tk command and sends it to the
tk shell, which itself sends it to the associated Tk window (or the related widget).
The tk shell will run as long as
a - Python decides to close it for you (e.g. after the main (Tk()) window has been destroyed)
b - you explicitely close it calling the widget's quit() method
c - a fatal tk error occurs, so the tk shell decides to quit itself
Now most of the errors that occur happen of course on the python level and are caught
by the python interpreter (that shows you the traceback) and there is no reason
for python to inform the tk shell that it should quit.
I hope this makes sense
More information about the Tutor