ron800 has asked for the wisdom of the Perl Monks concerning the following question:

I want to create a set of check buttons, based on names in an array. The final checkbutton will be one that allows user to select all or de-select all the other check buttons. That is, the last one is a button with a call to a subroutine that performs the all select or deselect. Any ideas on how to do this?
for my $x (@structured_options) { $types_selected{$x}=0; my $structuredb = $structured_frame->new_ttk__checkbutton( -text => $x, -onvalue => 1, -offvalue => 0, -variable =>\$types_selected{$x}, ); $structuredb->g_pack(-side => "left"); } my $imagec = $image_frame->new_ttk__checkbutton( -text => 'All', -onvalue => 1, -offvalue => 0, -variable =>\$all_images, -command => sub{ select_all() }, ); $imagec->g_pack(-side => "left");

Replies are listed 'Best First'.
Re: Tkx select/deselect checkbuttons
by blindluke (Hermit) on Nov 11, 2014 at 20:34 UTC

    I think that a simple call to the select method of every checkbox will be enough. Something like:

    sub select_all { my @cbxs = @_; for my $cb (@cbxs) { $cb->select( ); } }

    "Mastering Perl/Tk" is a good reference, when you're dealing with Tk.

    - Luke

      Thank you, Luke. By setting the checkbutton to 1/0, I was able to get it to work.
Re: Tkx select/deselect checkbuttons
by Anonymous Monk on Nov 12, 2014 at 01:59 UTC