Use different frames to separate widgets in columns when you are using pack, or use other geometry managers like grid, frame or place. A good source of inspiration is the widget demo script that comes with TK (enter 'widget' in the console).

The anchor option is for alignment.

use 5.010; # for say use strict; use warnings; use Tk; my $main = MainWindow->new(); my $label = $main->Label( -text => "Presence Check" )->pack(); my $opt_ft = [qw/-side top -expand 1 -fill both/]; my $opt_flr = [qw/-side left -expand 1 -fill both/]; my $opt_fb = [qw/-side bottom -expand 1 -fill both/]; my $opt_c = [qw/-side top -pady 2 -anchor w/]; my $fr_top = $main->Frame()->pack(@$opt_ft); my $fr_top_l = $fr_top->Frame()->pack(@$opt_flr); my $fr_top_r = $fr_top->Frame()->pack(@$opt_flr); my $fr_bot = $main->Frame()->pack(@$opt_fb); my ( $vbutton1, $vbutton2, $vbutton3 ) = ( 'OFF', 'ON', 'OFF' ); my $b1 = [ [ 'button1', 'button 1', \$vbutton1, 'OFF', 'ON' ], [ 'button2', 'button 2', \$vbutton2, 'OFF', 'ON' ], [ 'button3', 'button 3', \$vbutton3, 'OFF', 'ON' ], ]; foreach my $btn (@$b1) { $fr_top_l->Checkbutton( -text => $btn->[1], -variable => \$btn->[2], -offvalue => $btn->[3], -onvalue => $btn->[4], )->pack(@$opt_c); } my ( $vbutton4, $vbutton5 ) = ( 'ON', 'OFF' ); my $b2 = [ [ 'button4', 'button 4', \$vbutton4, 'OFF', 'ON' ], [ 'button5', 'button 5', \$vbutton5, 'OFF', 'ON' ], ]; foreach my $btn (@$b2) { $fr_top_r->Checkbutton( -text => $btn->[1], -variable => \$btn->[2], -offvalue => $btn->[3], -onvalue => $btn->[4], )->pack(@$opt_c); } my $button = $fr_bot->Button( -text => "Exit", -command => \&exit_button )->pack(@$opt_ft); MainLoop(); sub exit_button { foreach my $btn (@$b1) { say "- $btn->[0]: $btn->[1] -> ${$btn->[2]}"; } foreach my $btn (@$b2) { say "- $btn->[0]: $btn->[1] -> ${$btn->[2]}"; } $main->destroy; }

Regards, Stefan.


In reply to Re: PERL tk module handling by stefbv
in thread PERL tk module handling by michael99

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.