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'); }

In reply to Reuse Tk:Frame -solved by glenn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.