One way to arrange things in 2 rows of 3 each is to divide your area into 2 Tk::Frames:

Red  Green  Blue <-- Top frame
Mustard  Vinegar  Salt <-- Bottom frame
Then pack each row into its frame, left-to-right:
my $mw = new Tk::MainWindow; my $top = $mw->Frame->pack; my $bottom = $mw->Frame->pack; my @cb = ((map { $top->Checkbutton(-text => $_)->pack(-side => 'left') + } qw{Red Green Blue}), (map { $bottom->Checkbutton(-text => $_)->pack(-side => 'left') +} qw{Mustard Vinegar Salt})); MainLoop;

Of course, this keeps the widths of different buttons independent. If you want everything nicely gridded out, use the Tk::grid geometry manager instead of Tk::pack. This lets you align everything, a bit like this:

RedGreenBlue
MustardVinegarSalt
You'll probably want to stick each Checkbutton to the east side of its box, too:
my $mw = new Tk::MainWindow; my @cb = ((map { $mw->Checkbutton(-text => (qw{Red Green Blue})[$_])-> grid(-column => $_, -row => 0, -sticky => 'w') } 0..2), (map { $mw->Checkbutton(-text => (qw{Mustard Vinegar Salt})[$_]) +-> grid(-column => $_, -row => 1, -sticky => 'w') } 0..2)); MainLoop;


ariels -- Add table to explicate the thing with the grid.

In reply to Re: Lining up check boxes in Tk by ariels
in thread Lining up check boxes in Tk by Popcorn Dave

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, details, 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, summary, 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.