John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

My GUI has an upper section and a lower section. When I resize the window vertically, it keeps the same relative proportion between the two sections. That is, when I grow the window, the upper part grows also. I don't want the upper part to grow. When I shrink the window the upper pane doesn't get any smaller (until it runs out of room completely), which is good. The pack options take care of that just fine. But I can't get the top to not grow, but simply keep the same size period.

As for horizontal sizing, I got it to put all the new space in the rightmost column, which is what I wanted. I can't seem to do the same thing in the Y direction, though.

Can someone please help?

I've included the GUI part of my script.

use strict; use Tk; my $mw= new MainWindow::; my @version= (2,0,0,''); my $date= "21-Nov-2002"; my $option= 'analyze'; my ($directory)= "blah blah"; my $textbox; my $checkout_command= "foo bar %f"; sub params_box { my $top= $mw->Frame; my $f2= $top->Frame()->pack (-side=>'left', -anchor=>'n', -pady=>5); # Iteration/Revision/Patch info my $f1= $f2->Frame()->pack (-side => 'top', -pady=>2); $f1->Label (-text => "Iteration: ")->pack (-side => 'left'); $f1->Entry (-width=>3, -textvariable=>\$version[0] )->pack (-side => +'left'); $f1->Label (-text => "Revision: ")->pack (-side => 'left'); $f1->Entry (-width =>3, -textvariable=>\$version[2] )->pack (-side => + 'left'); $f1= $f2->Frame->pack (-side=>'top', -anchor=>'w', -pady=>2); $f1->Label (-text => "Patch Level: ")->pack (-side =>'left'); $f1->Entry (-width=>3, -textvariable=>\$version[3])->pack (-side=>'le +ft', -expand=>1, -fill=>'x'); # Release Date $f1= $f2->Frame->pack (-side => 'top', -pady=>2); $f1->Label (-text => "Release Date:")->pack (-side => 'left'); $f1->Entry (-width => 12, -textvariable=>\$date)->pack (-side => 'lef +t'); # make a stack of buttons $f2= $top->Frame()->pack(-side => 'left', -padx=>7, -pady=>5, -anchor +=>'n'); $f2->Button (-text => 'Go', -width => 10, -pady => 0, -command => \&g +o ) ->pack (-side => 'top', -expand => 1, -padx => 1, -pady => 1); $f2->Button (-text => 'Exit', -width => 10, -pady => 0, -command => \ +&exit ) ->pack (-side => 'top', -expand => 1, -padx => 1, -pady => 1); $f2->Button (-text => 'Clear', -width => 10, -pady => 0, -command => +sub{print OUTPUT "\x19"} ) ->pack (-side => 'top', -expand => 1, -padx => 1, -pady => 1); # the options $f2= $top->Frame (-relief=>'groove', -borderwidth=>2)->pack(-side=>'l +eft'); $f2->Radiobutton (-text => 'Check files out of Continuus', -value=>'c +heckout', -variable=>\$option) ->pack (-side => 'top', -anchor=>'w'); $f2->Radiobutton (-text => 'Defeat R attribute on read-only files', - +value=>'defeat', -variable=>\$option) ->pack (-side => 'top', -anchor=>'w'); $f2->Radiobutton (-text => 'analyze only (don\'t modify files)', -val +ue=>'analyze', -variable=>\$option) ->pack (-side => 'top', -anchor=>'w'); $f2->Radiobutton (-text => 'write different files (for testing)', -va +lue=>'temp', -variable=>\$option) ->pack (-side => 'top', -anchor=>'w'); # other fields $f2= $top->Frame()->pack(-side=>'right', -fill=>'x', -expand=>1, -anc +hor=>'n', -pady=>5); $f2->Label (-text => 'Working Directory:', -anchor=>'e') -> grid ( $f2->Entry (-textvariable=>\$directory), -sticky => 'ew'); $f2->Label (-text => 'CheckOut Command:', -anchor=>'e') -> grid ( $f2->Entry (-textvariable=>\$checkout_command), -sticky => 'ew'); $f2->gridColumnconfigure (1, -weight=>1); return $top; } sub setup_main_window { params_box()->pack (-side => 'top', -anchor=>'w', -expand=>1, -fill=> +'x'); $textbox= $mw->Scrolled ('ROText', -scrollbars=>'ose', -height=>20, - +width=>132) -> pack (-side=>'bottom', -expand=>1, -fill=>'both') ->Subwidget ('rotext'); } setup_main_window(); $textbox->insert ('end', "blah blah blah $_\n") for (1..50); MainLoop();
—John

Replies are listed 'Best First'.
Re: Tk window panes not resizing the way I want
by traveler (Parson) on Nov 21, 2002 at 21:24 UTC
    Changing
    params_box()->pack (-side => 'top', -anchor=>'w', -expand=>1, -fill=>' +x');
    to
    params_box()->pack (-side => 'top', -anchor=>'w', -expand=>0);
    seems to do it.

    --traveler

      Well, that messes up the horizontal direction. It doesn't expand the rightmost text boxes to fill the available space, and doesn't resize in the X direction as the window changes width.
        OOPS, I missed that criterion. Then try the line:
        params_box()->pack (-side => 'top', -anchor=>'w', -expand=>0, -fill=>' +x');
        This causes width expansion to all be in the rightmost part. Is that what you want?

        --traveler