Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-19 20:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found