Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Tcl/Tk] another window beside my gui - how to avoid it?

102 views
Skip to first unread message

Guy

unread,
Jun 22, 2011, 9:09:08 AM6/22/11
to
Hi,

When my script starts, beside the GUI i'v created in my script - there is another window that appears.
How can i avoid this other window?

Thanks,
Guy

APN

unread,
Jun 22, 2011, 9:26:19 AM6/22/11
to

Are you using toplevel to create your window? If so, you probably need
to do a "wm withdraw ." to withdraw the "." toplevel. Alternatively,
just build your widgets in "." instead of creating a new toplevel

/Ashok

Guy

unread,
Jun 22, 2011, 9:58:09 AM6/22/11
to
Thank you very much!
the "wm withdraw ." works just fine...

Robert Heller

unread,
Jun 22, 2011, 10:39:08 AM6/22/11
to

Are you doing something like:

set mygui [toplevel .mygui]

and then building your gui in .mygui?

You don't need to create a new toplevel to build your gui in. You can
use the main toplevel created automatically. It is called '.' and you
can build your gui there.

Alternitively, you can include this line:

wm withdraw .

in your script, if there is some reason you cannot just build your main
GUI in the root window (.).

>
> Thanks,
> Guy
>

--
Robert Heller -- 978-544-6933 / hel...@deepsoft.com
Deepwoods Software -- http://www.deepsoft.com/
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments



CARLO KOKOTH

unread,
Jun 22, 2011, 10:45:45 AM6/22/11
to
On Jun 22, 3:58 pm, Guy <gelimel...@gmail.com> wrote:
> Thank you very much!
> the "wm withdraw ." works just fine...

Be aware of the fact that the main window (the window called .) is
special in that the whole application is closed when the windows is
closed.

When you hide / withdraw the main (.) window, you have to take care to
call exit when ie. the last window is closed, otherwise the process
stays hanging in the background.

Conversely, you have to take care to catch close window request when
you use the . window and want the application to keep running (only
hide the . window) when user closes the window (wm protocol .
WM_DELETE_WINDOW <HANDLER_PROC>).

Guy

unread,
Jun 23, 2011, 3:25:37 AM6/23/11
to
actually, this is how i start my gui:

#############################
toplevel .reltop
wm title .reltop "Release Prep"
wm withdraw .
##############################

The "wm withdraw ." statement works just fine. it hides my "." window and when i exit the gui it leaves nothing running.

I didnt understand what this statement does...


(wm protocol .
WM_DELETE_WINDOW <HANDLER_PROC>)

Guy

Arjen Markus

unread,
Jun 23, 2011, 6:58:43 AM6/23/11
to
On 23 jun, 09:25, Guy <gelimel...@gmail.com> wrote:
>
> I didnt understand what this statement does...
> (wm protocol .
> WM_DELETE_WINDOW <HANDLER_PROC>)
>
> Guy

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)

Regards,

Arjen

Richard Owlett

unread,
Jun 24, 2011, 1:44:30 PM6/24/11
to

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.

TIA


Robert Heller

unread,
Jun 24, 2011, 2:11:23 PM6/24/11
to

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
exit
}

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}

>
> TIA

Gerald W. Lester

unread,
Jun 24, 2011, 3:37:35 PM6/24/11
to Robert Heller

Instead of exit, you really should use: destroy .

--
+------------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald...@kng-consulting.net |
+------------------------------------------------------------------------+

Robert Heller

unread,
Jun 24, 2011, 3:58:24 PM6/24/11
to

Does this really make a difference?

Gerald W. Lester

unread,
Jun 24, 2011, 4:38:55 PM6/24/11
to

Yes, if you have outstanding events -- destroy . processes those before
shutting down, exit does not.

Richard Owlett

unread,
Jun 24, 2011, 5:49:55 PM6/24/11
to
Thank you.
0 new messages