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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a new Window, by destroying one.

Status
Not open for further replies.

gammaman64

Programmer
Apr 28, 2007
9
US
Is there a way to create a new MainWindow, by destroying
another one?
 
Your program only needs one MainWindow. Use Toplevel if you want new windows that act like MainWindows.

Code:
my $mw = MainWindow->new (
   -title => 'Main Window',
);

# create a new window
my $child = $mw->Toplevel (
   -title => 'Another window',
);

# and a new one?
my $another_child = $mw->Toplevel (
   -title => 'Yet another window',
);

MainWindow is, itself, a Toplevel, albeit a special kind of Toplevel. Toplevels act the same as MainWindows, being totally independent of one another. However, if you destroy the MainWindow, all Toplevels that it created are destroyed as well; however, you can destroy its Toplevels without the other Toplevels being destroyed.

If you want to show/hide a window without destroying/remaking it:

Code:
# hide
$window->withdraw;

# show again
$window->deiconify;

So... if you want to, you could create a MainWindow, and withdraw it, and have your application use only Toplevels (since the MW is withdrawn, it isn't visible on the screen, but it hasn't been destroyed, so its Toplevels can still exist just fine).

However, if you do that, make sure you destroy the MainWindow when the last Toplevel is destroyed, otherwise your script will continue running even after you've closed all of the Toplevels.

-------------
Cuvou.com | The NEW Kirsle.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top