Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Reuse Tk:Frame -solved

by glenn (Scribe)
on May 27, 2015 at 14:01 UTC ( #1128001=perlquestion: print w/replies, xml ) Need Help??

glenn has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, back again with another Tk question. I want to reuse a frame in main window to show different information based on what the user selects. I am trying to avoid having to destroy and recreate all the widgets as a user goes into a sub section and back out. This is a very simplified working example code of what I want to do (except it does not load the widgets and will eventually run out of mem, hence my Q). Basically there are multiple systems monitored and buttons for each system to show sub information on that system. Thanks.

Only Unmap/Map a FRAME not the widgets within

use Tk; my $mainwindow; my @save; mw(); MainLoop(); sub mw { $mainwindow = MainWindow->new(); my $frm1 = $mainwindow->Frame(-borderwidth=>4, -relief=>"ridge")-> +pack(-side=>'top', -expand=>1, -fill=>"x", -anchor=>"n"); my $frm2 = $mainwindow->Frame(-borderwidth=>4, -relief=>"ridge")-> +pack(-side=>'top', -expand=>1, -fill=>"both", -anchor=>"n"); my $frm3 = $mainwindow->Frame(-borderwidth=>4, -relief=>"ridge")-> +pack(-side=>'top', -expand=>1, -fill=>"x", -anchor=>"n"); $frm1->Label(-text=>"TITLE")->pack(-side=>'top'); $frm3->Button(-text=>"Hide Restore", -command=>sub{ if (@save) { print join("\n",@save)."\n"; foreach my $child (@save) { push(@save, $child); $child->MapWindow(); } } else { print join("\n",$frm2->children())."\n"; foreach my $child ($frm2->children()) { push(@save, $child); $child->UnmapWindow(); } } $mainwindow->update(); })->pack(-side=>'top'); $frm2->Label(-text=>"buttons to specific data")->pack(-side=>'top' +); $frm2->Label(-text=>"buttons to specific data")->pack(-side=>'top' +); $frm2->Label(-text=>"buttons to specific data")->pack(-side=>'top' +); $frm2->Label(-text=>"buttons to specific data")->pack(-side=>'top' +); $frm2->Label(-text=>"buttons to specific data")->pack(-side=>'top' +); }

solution

use Tk; my $mainwindow; my $save=0; mw(); MainLoop(); sub mw { $mainwindow = MainWindow->new(); my $frm1 = $mainwindow->Frame(-borderwidth=>4, -relief=>"ridge")-> +pack(-side=>'top', -expand=>1, -fill=>"x", -anchor=>"n"); my $frm2 = $mainwindow->Frame(-borderwidth=>4, -relief=>"ridge")-> +pack(-side=>'top', -expand=>1, -fill=>"both", -anchor=>"n"); my $frm3 = $mainwindow->Frame(-borderwidth=>4, -relief=>"ridge")-> +pack(-side=>'top', -expand=>1, -fill=>"x", -anchor=>"n"); my $container = $frm2->Frame(-borderwidth=>4, -relief=>"ridge")->p +ack(-side=>'top', -expand=>1, -fill=>"both", -anchor=>"n"); $frm1->Label(-text=>"TITLE")->pack(-side=>'top'); $frm3->Button(-text=>"Hide Restore", -command=>sub{ if ($save) { $container->MapWindow(); $container->raise; $save=0; } else { $container->UnmapWindow(); $save=1; } return; })->pack(-side=>'top'); $container->Label(-text=>"buttons to specific data")->pack(-side=> +'top'); $container->Label(-text=>"buttons to specific data")->pack(-side=> +'top'); $container->Label(-text=>"buttons to specific data")->pack(-side=> +'top'); $container->Label(-text=>"buttons to specific data")->pack(-side=> +'top'); $container->Label(-text=>"buttons to specific data")->pack(-side=> +'top'); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1128001]
Approved by GotToBTru
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2022-01-18 17:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (53 votes). Check out past polls.

    Notices?