http://www.perlmonks.org?node_id=1218559

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

I have been struggling with the -sticky option with Tk::grid. It does not seem to want to stretch a container for me.

In this simple example I use $gridOrPack to select whether I will grid or pack 2 frames. Then I add a label to one frame and a button to the other frame...

when I set $gridOrPack to 'pack' I pack with -expand=>1 and fill=>'both', It behaves just like I want... the frames stretch to fill the mainWindow

when I set $gridOrPack to 'grid' I grid with the -sticky option set to 'nsew' (I've also tried 'ew' and 'ns') and the frames do not stretch.

Am I missing something silly?

use strict; use Tk; use Tk::LabFrame; use Tk::Treeplus; use Tk::ErrorDialog; my $mw = MainWindow->new(); my $gridOrPack="grid"; #"pack"; #my $gridOrPack="pack"; my $tpFrame; my $butFrame; my $tpFrame=$mw->LabFrame(-label=>'TreePlusFrame'); my $butFrame=$mw->LabFrame(-label=>'ButtonFrame'); if ($gridOrPack=~/grid/i) { $tpFrame->grid(-row=>1, -column=>1, -sticky=>'ew'); $butFrame->grid(-row=>2, -column=>1, -sticky=>'ew'); } else { $tpFrame->pack(-side=>'top',-expand=>1,-fill=>'both'); $butFrame->pack(-side=>'top',-expand=>1, -fill=>'both'); } $tpFrame->Label(-text=>'I like pack better')->pack(-side=>'top'); $butFrame->Button( -text => 'Exit', -command => sub { exit(0) }, ) ->pack(qw(-side bottom -pady 10)); MainLoop();