in reply to perltk autoresize following users resize

This may help
#!/usr/bin/perl use Tk; my $mw = MainWindow->new; $mw->bind( "<Configure>" => sub { print "reconfigure ".ref($_[0]). +"\n" } ); my $topFr = $mw->Frame ->pack( -fill => "both", -expand => 1 ); $topFr->Button( -text => "bigger", -command => sub { changeSize(50) } +) ->pack( -side => "bottom", -expand => 1 ); $topFr->Button( -text => "smaller", -command => sub { changeSize(-50) +} ) ->pack( -side => "bottom", -expand => 1 ); my $interior = $topFr->Frame( -label => "Hello world", -height => 100, -width => 100, -background => "white", -relief => "groove" ) ->pack( -side => "bottom", -fill => "both", -expand => 1 ); $interior->packPropagate(0); MainLoop; sub changeSize { my ($sizeDelta) = @_; $interior->configure( -width => $interior->width+$sizeDelta, -height => $interior->height+$sizeDelta ); printf("interior %d x %d, topFr %d x %d\n", $interior->width, $interior->height, $topFr->width, $topFr->height ); }
#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = new MainWindow; my $current_size = $mw->reqwidth . "x" . $mw->reqheight; my $old_current_size = $current_size; $mw->bind( '<Configure>', sub{ &OnResize }); my $leave = 0; $mw->bind( '<Leave>',sub { $leave = 1; } ); $mw->bind( '<Enter>',sub { $leave = 0; &OnResize; } ); MainLoop; sub OnResize { my $current_size = $mw->width . "x" . $mw->height; if( $leave == 1) {return } if($old_current_size eq $current_size){return} ## Resize has occurred do something: printf( "Resize happened - old size: %s, new size: %s\n", $old_current_size, $current_size ); ## set the old size to the new size $old_current_size = $current_size; }

I'm not really a human, but I play one on earth Remember How Lucky You Are

Replies are listed 'Best First'.
Re^2: perltk autoresize following users resize
by rpelak (Sexton) on Aug 19, 2008 at 15:10 UTC
    zentara's post was the most helpful. But I was hoping there was a way to just turn the auto resizer back on, not to have to force the window to a given size.
    Example...
    window is 100 tall. Containing a listbox. listbox is 25 tall. User wants so see more of the list box without scrolling, so they drag the window to 125. Widgets are setup so that the listbox expands to 50, and nothing else does. Then user checks a checkbox that causes the packing of an additional listbox in the gui. If the user hadn't manually resized the window, it would just expand to give space to the new listbox. But since they did, it will not change size, and the bottom of the form will run off the bottom of the window.
    of course since I know the size of the new listbox, I could increase the size of the window, but that would mean keeping track of sizes for everything that can be packed and unpacked, which is a lot of things. Too many in fact to be rational to do.
    all said and done, it sounds like this solution doesn't scale well to large apps. Randell
      I'm not sure exactly what you want, but it sounds like you are looking for a Tk::Adjuster. See Tk::Adjuster, how to keep proportions for maintaining ratios. Here is a simple example with no ratio.
      #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Pane; my $mw = MainWindow->new(); my $pane = $mw->Scrolled('Pane', -sticky => 'nsew', -scrollbars => 'osoe', )->pack(-fill => 'both',-expand => 1); my $i; for ($i = 0; $i <= 5; $i++){ my $frame = $pane->Frame( -relief => 'ridge', -bd => 1,) ->pack(-side => 'top',-fill => 'both',-expand => 1); my $adjust = $pane->Adjuster(); $adjust->packAfter($frame, -side => 'top',-fill=>'both',-expand=>1); my $label = $frame->Label(-width => 30, -text => "Frame ". $i,)->pack(); } my $frame = $pane->Frame( -relief => 'ridge', -bd => 1,) ->pack(-side => 'top',-fill => 'both',-expand => 1); my $label = $frame->Label(-width => 30, -text => "Frame 6 ")->pack(); MainLoop;

      I'm not really a human, but I play one on earth Remember How Lucky You Are
        I looked at the adjuster and it didn't do what I needed... so let me try to explain better.

        I have a window, I put in a labeledframe which we can call foo. In it, I put a checkbox (enable foo) and a frame(which I use as a kind of container). If you uncheck the checkbox, the container frame is packForget'ed. If you recheck it, it is pack'ed. By default, the whole window resizes after each change. But if while it is unchecked, the user resizes the window slightly (in the y direction), then if they check the checkbox it will not resize to fit the new contents, causing them to be off the bottom of the gui.

        So when the user does a manual resize, it does something to stop the automatic resizing. I want to turn the auto resizing back on.

        Of course I could manually handle the resizing in this case, but in the real case there are just too many widgets and too many other things to make that effective.

        Randell