in reply to Tk List of Checkboxes?
BTW, this is made up from fragments scrounged from Mastering Perl/Tk. The comments are from the book as well.use strict; use Tk; my $mw = MainWindow->new(); # Create the vertical Scrollbar my $scrollbar = $mw->Scrollbar(); my $lb = $mw->Listbox(-yscrollcommand => ['set' => $scrollbar]); # Configure the Scrollbar to talk to the Listbox widget $scrollbar->configure(-command => ['yview' => $lb]); # Pack the Scrollbar first so that it doesn't disappear when we resize $scrollbar->pack(-side => 'right', -fill => 'y'); $lb->pack(-side => 'left', -fill => 'both'); my %cb; foreach ( qw/a b c d e f g h/ ) { $lb->Checkbutton(-text => "$_", -variable => \$cb{"cb$_"}) -> pack(-side => 'top'); } MainLoop();
--Jim
Update: After some digging, I'd recommend that you follow the suggestion by Util. I'm not sure what led me to try and embed checkboxes into a listbox widget (one example in the book gives an example packing entry widgets into a text widget, but the whole idea of inserting multiple widgets into either text or listbox widgets seems convoluted and flawed to me).
One alternative is to use a listbox instead of several checkboxes using the "-selectmode => multiple" option, but it appears to work correctly only on NT class boxes (on lesser boxes it ignores the multiselect and uses single select).
|
|---|