It works basically like this. You need one Mainloop running, so you need to keep 1 mainwindow going, even if it is withdrawn from view. Once you have the Mainloop, you can create any number of toplevel windows controlled by that loop. If you start creating new toplevels, then destroying them, and you see memory gain, you can go to the more advanced method using packForget. You can take any window, withdraw it, run packForget on all it's packChildren, repack it with fresh widgets, then raise it back up. If you are going to juggle alot windows with different widgets packed into them, it is best to use the packForget method, so you have fewer windows created-destroyed.
The idea is you can reuse existing windows. Furthermore, you can reuse any widgets by withdrawing them, reconfiguring them, then repacking them. Here is a basic example: (I didn't reuse the cb widgets, but reused the frame and maindow.
#!/usr/bin/perl use warnings; use strict; use Tk; my $top = new MainWindow; my @counts = ('a'..'z'); my %cbuttons; my $frame = $top->Frame()->pack(); setup_page(); $top->Button(-text => "packForget", -command => sub{ my @w = $frame->packSlaves; foreach (@w) { $_->packForget; } })->pack(); $top->Button(-text => "repack", -command => sub{ &setup_page })->pack(); $top->Button(-text => "Exit", -command => sub {exit})->pack; MainLoop; sub setup_page{ for (1..4){ my $text = shift @counts; $cbuttons{$_}{'cb'} = $frame->Checkbutton( -text => $text, -variable => \$cbuttons{$_}{'val'}, -command => \&SetState, )->pack; } }
In reply to Re: perlTk opening new window
by zentara
in thread perlTk opening new window
by wisemonkey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |