[Tkinter-discuss] main window closing when dialogs are open

Michael Lange klappnase at web.de
Tue Oct 17 12:02:13 CEST 2006

On Tue, 17 Oct 2006 10:02:35 +0200
Bencsik Roland <roland.bencsik at ludensis.hu> wrote:

> Hi Michael,
> Although your version works well, I am still not satisfied with the 
> result, because the user does not know why the program is still running 
> when she pressed the close button.
> So, currently I route the WM_DELETE_WINDOW to a warning dialog which 
> asks the user to use the quit method what the program offer. 
> Unfortunately this version also has a problem that in some cases the 
> warning dialog erases the already popped up dialog.
> Best would be if somehow all the windows and dialogs could be closed and 
> the program be terminated after the clean up tasks are done.

Hi Roland,

I don't know if this is possible at all, even sys.exit() does not seem to work.
Maybe instead of the additional warning dialog you could change the WM_DELETE_WINDOW
callback while the dialog is up, like

    def info(self):
        self.owner.protocol('WM_DELETE_WINDOW', self.bell)
        self.owner.protocol('WM_DELETE_WINDOW', self.quit)

However this might become complicated in a bigger app with lots of message boxes.
Maybe a separate messagebox module would help.

Alternatively you could write your own replacement for tkMessageBox; if the
dialog is derived from Toplevel you should be able to close all windows from
the main window's "close" button.


More information about the Tkinter-discuss mailing list