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

Hello Monks,

My program is not behaving as expected, and I'm hoping you can explain why. I'm guessing it has something to do with the way I'm packing the frames, but I have tried many variations of the options and am still having problems.

My main window contains two frames, one on the left and one on the right. My intent is that when I widen the main window, the left frame will remain anchored to the left side of the main window and will not grow in X. This works as desired. The right frame is supposed to grow to fill all the area not used by the left frame. This does not happen. Although the right frame does expand some, its left side pulls away from the left frame, exposing an empty area of the main window.

Below is a complete program that demonstrates the problem.

I suspect it's something simple, but I can't figure it out. Can someone take a look and enlghten me?

Thanks!

use strict; use warnings; use Tk qw(MainLoop); my $mw = MainWindow->new( -bg => 'gold'); my $ctl = $mw->Frame(-borderwidth => 1, -relief => 'solid', -width => 300, -bg => 'aquamarine', )->pack(-fill=>'y', -expand=>1, -side=>'left', -anchor => 'w', ); my $cbox = $mw->Frame(-borderwidth => 1, -relief => 'solid', -width => 300, -height => 500, -bg => 'cornflowerblue', )->pack(-fill => "both", -expand => 1, -side=>'left', -anchor => 'w', ); + my $sfrm = $ctl->Frame()->pack(-fill=>'y', -expand=>0, -side=>'left' +,); $sfrm->Scale(-from => 255, -to => 0, )->pack(-fill=>'y', -expand=>1, -side=>'top',); MainLoop();

Replies are listed 'Best First'.
Re: Question about packing frames
by tybalt89 (Monsignor) on Oct 21, 2019 at 22:17 UTC

    Change this line

    )->pack(-fill=>'y', -expand=>1,

    to

    )->pack(-fill=>'y', -expand=>0,

      Thanks for your reply, but this change does not affect the unwanted behavior.

      Here is some more detail. The left frame is the $ctl frame. It contains some widgets. The right frame is the $cbox frame. It is empty. The background of the $cbox frame is blue. The background of the main window is yellow. If I use the cursor to manually widen the main window, the $cbox frame pulls away from the $ctl frame, exposing a portion of the main window (yellow) in between. This is what I want to change. I want the $cbox frame to occupy all the area to the right of the $ctl frame, no matter how big I make the main window.

        I just noticed there is more than one -expand=>1
        Change the first one.

        Here's more context:

        my $ctl = $mw->Frame(-borderwidth => 1, -relief => 'solid', -width => 300, -bg => 'aquamarine', )->pack( -side=>'left', -fill=>'y', -expand=>0, -anchor => 'w', );

        That change works for me.
        It does exactly what you say you want. It does not expose any yellow.
        Are you sure you are running the changed code?