Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Tk List of Checkboxes?

by jlongino (Parson)
on Jun 09, 2002 at 20:28 UTC ( [id://172958]=note: print w/replies, xml ) Need Help??


in reply to Tk List of Checkboxes?

First, let me say that this is only the third or fourth Tk script I've fooled with so this is as much a learning process for me as it is you (if not moreso). I've tried this little script and I think it has the elements you've described. The only problem is that although it looks right, it doesn't scroll. So maybe you can use this as a starting point and do some research from there. I'll keep working on it as well, and hopefully one of us or some more experienced and merciful monk will figure it out.
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();
BTW, this is made up from fragments scrounged from Mastering Perl/Tk. The comments are from the book as well.

--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).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (None)
    As of 2024-04-25 01:53 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found