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

Re: Lining up check boxes in Tk

by ariels (Curate)
on Apr 21, 2002 at 07:48 UTC ( [id://160854]=note: print w/replies, xml ) Need Help??


in reply to Lining up check boxes in Tk

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://160854]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-04-24 06:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found