Re: Question raised by answer to [Re: another window beside my gui - how to avoid it?]

At Fri, 24 Jun 2011 14:37:35 -0500 "Gerald W. Lester" <Gerald.Lester@xxxxxxxxxxxxxxxxxx> wrote:

On 6/24/11 1:11 PM, Robert Heller wrote:
At Fri, 24 Jun 2011 12:44:30 -0500 Richard Owlett<rowlett@xxxxxxxxxxxx> wrote:

Arjen Markus wrote:
On 23 jun, 09:25, Guy<gelimel...@xxxxxxxxx> wrote:

I didnt understand what this statement does...
(wm protocol .


That line causes your program to invoke the registered procedure
(whatever HANDLER_PROC
you specified) when the user presses the little x i the upper-right
corner. Otherwise
your program will simply stop (or even worse: the toplevel window
becomes invisible and
your program does not interact with the user anymore)



At the end of a script, how do I force a clean exit?
IE flush and close all open files and destroy any windows which
have been withdrawn.
I know I've seen a reference somewhere, but I don't know what to
search for.

The exit command will do that.

In the case of a GUI program, you don't want to just put 'exit' at the
end of the script. The program will exit *before* displaying the GUI!
Presumably your GUI has a 'quit' or 'close' or 'done' or 'finish'
button. What ever callback script you have bound to this button would
call exit as the last thing it does.

You can also (and probably *should* in the case of withdrawing . and
using another toplevel as your GUI window) include something like this:

wm protocol .mytoplevelgui WM_DELETE_WINDOW {MyExitProc}

proc MyExitProc {} {
# (optional) Confirm exit
if {![tk_messageBox -type yesno -icon question \
-message "Are you sure you want to exit?"]} {return}
# Do whatever application specific cleanup needed

It is really *best* to put your main GUI in the mail (.) window and then
bind to its WM_DELETE_WINDOW some appropiate exit proeduure:

wm protocol . WM_DELETE_WINDOW {MyExitProc}

Instead of exit, you really should use: destroy .

Does this really make a difference?

Robert Heller -- 978-544-6933 / heller@xxxxxxxxxxxx
Deepwoods Software --
() ascii ribbon campaign -- against html e-mail
/\ -- against proprietary attachments