#!/usr/bin/perl use strict; use Tk; # @checkboxes is an array of two-element arrays, each of which # provides a label in element 0 and a value in element 1. # A reference to element 1 is given to the -variable option # of Tk::Checkbutton. my @checkboxes = ( ['First Checkbox' => 0], ['Second Checkbox' => 0], ['Third Checkbox' => 0], ); my $mw = tkinit; MakeCBs($mw, 'Label:', @checkboxes); $mw->Button( -text => 'Print checkbox values', -command => sub { foreach (@checkboxes) {printf "%s: %s\n", $$_[0], $$_[1]} }, )->pack; MainLoop; sub MakeCBs { my ($w, $label, @cbs) = @_; $w->Label(-text => $label)->pack(-side => 'left'); foreach (@cbs) { $w->Checkbutton( -text => $$_[0], -variable => \$$_[1], )->pack(-anchor => 'w'); } }
In reply to Re: print the values of the selected check buttons
by zentara
in thread print the values of the selected check buttons
by amboxer21
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |