Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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();

In reply to Tk::grid -sticky option not stretching frames by boleary

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (9)
    As of 2020-01-20 20:45 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?