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; }