A Tcl application can have multiple toplevel windows. One is created for you automatically, and its widget name is "." You can create additional toplevel windows using the
toplevel command; the result is similar to creating a frame widget. You can then create other widgets as children of the other toplevel,
pack or
grid them into the toplevel, etc.
Also, as you noticed, the main window "." has special meaning to your application. If "." is destroyed, your application exits. This is standard
wish behavior. Admittedly, in some situations you don't want the main window to appear. For example, you might have an application in which you display multiple documents, each in a separate window. You want users to be able to open and close documents on demand, and not exit until all documents are closed. In a case like this, you can hide ".", create a separate toplevel for each document, and then quit the application only when the last visible window is destroyed.
To hide a toplevel, use the
wm withdraw command. To display a toplevel, use the
wm deiconify command. For example:
Code:
wm withdraw . ;# Hide the main window
wm deiconify . ;# Redisplay the main window
Here's a very simple example of an application that creates and destroys a secondary toplevel window on demand:
Code:
proc DisplayDialog {} {
# Create the new toplevel window
toplevel .dialog
# Create some widgets and pack them into
# the new toplevel
label .dialog.msg -text "You have mail!"
pack .dialog.msg -padx 4 -pady 4
button .dialog.ok -text "Ok" -command {destroy .dialog}
pack .dialog.ok -padx 4 -pady 4
# Set the title of the toplevel
wm title .dialog "New Mail"
# Set the window's minimum size to be
# its initial size
update idletasks
wm minsize .dialog [winfo reqwidth .dialog] [winfo reqheight .dialog]
}
# The following code creates the interface
# for our main window
button .popup -text "Check Mail" -command DisplayDialog
button .quit -text "Quit" -command exit
pack .popup .quit -padx 4 -pady 4
- Ken Jones, President
Avia Training and Consulting
866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax