Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: PERL tk module handling

by stefbv (Curate)
on Apr 19, 2020 at 10:10 UTC ( #11115792=note: print w/replies, xml ) Need Help??


in reply to PERL tk module handling

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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (1)
As of 2021-10-21 02:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (82 votes). Check out past polls.

    Notices?