Still, if I'm honest, I think this is a limitation of Tk: imho their should be more automatic resize options than me coding and remembering the size of all frames.

Well, I think it maybe a widget layout design problem on your part, which probably can be easily fixed by carefully allowing all the child widgets to repack themselves, according to the new size.

If you want to remove a frameful of widgets, you should remove it's child widgets first with packForget. (Its like you can't remove a directory which still has subdirs). In other words, don't use complete Frame removal to remove a set of widgets, remove each widget itself, and leave the Frame. Then when you do a resize, and want to repack your frame, each widget gets repacked, and will do so according to the new reported size of the Frame they are being packed into.

I hope that made sense. Play with the following code, it creates new widgets on a rebuild, but you could repack your hidden widgets instead. A second example is also provided.

#!/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; } }
A second example:
#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new; my $vh = $mw->vrootheight; my $vw = $mw->vrootwidth; $mw->geometry($vw.'x'.$vh.'+0+0'); $mw->overrideredirect(1); #grabs full control $mw->fontCreate('big', -family=>'arial', -weight=>'bold', -size=>int(-18*18/14)); my $topframe = $mw->Frame->pack(); my $frame = $mw->Frame->pack(); my $txt; #make these globals so you reuse them my $canvas; #and avoid memory gains of making too many #redundant widgets my $count = 0; # instead of a button you could make navigation arrows $topframe->Button(-text => "Change Screen", -command => sub{ #clean out frame's children my @w = $frame->packSlaves; foreach (@w) { $_->packForget; } #clean out frame $frame->packForget; $count++; &build($count); })->pack(-side=>'left',-padx=>20); $topframe->Button(-text => "Exit", -command => sub {exit})->pack(-side=>'right',-padx=>20); &build(0); #setup first screen MainLoop; sub build { my $count = shift; $txt = $frame->Text(-bg=>'white',-font=>'big',-height=>5)->pack(-fill +=>'x'); $txt->insert('end',"\t\t\t\t Page $count"); # Note that the 'virtual window' height and width are $vh and $vw # respectively, so we use those dimensions for our Canvas height # and width, and let the Canvas expand and fill in both x and y # directions. # $canvas = $frame->Canvas( -width => $vw, -height => $vh, -background =>'blue', )->pack(-expand => 1, -fill => 'both'); $canvas->createRectangle(80, 80, 200, 200, -fill => 'yellow'); $canvas->createText(125, 125, -fill => 'black', -text => "page $count", -font => 'big', ); $frame->pack(); #reshow it $mw->update; }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re^9: resizing problem with Tk appl using PackForget by zentara
in thread resizing problem with Tk appl using PackForget by monger_39

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.