Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening two windows concurrently...

Status
Not open for further replies.

FreddieBlassie

Programmer
Dec 11, 2001
20
US
I have a frontend I created that I use to run various scripts. I am trying to open up a second widget through one of the scripts to field user data. The problem is, when I try to do that the second window doesnt appear (although it appears when the widget code is run independently). I tried to destroy the frontend window since it isn't really needed after the input is taken from it, and then create the second widget, but when I do that the whole console disappears and the process is completely terminated. Does anyone know how I can accomplish what I'm after or have any suggestions?
 
I'm not sure what problem you're encountering but you might try making the second widget in a "toplevel". Bob Rashkin
rrashkin@csc.com
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top