in reply to Tk List of Checkboxes?

Warning: I, too, am new to the Tk parts of Perl. I have Mastering Perl/Tk at the office, but have not yet read it.

jlongino, I think that there are two problems in your code:

  1. The $lb->pack( ... ) statement needs to have an extra parameter: -expand => 'yes' . This change makes it work better, but still not right.
  2. The Listbox widget does not expect to have other widgets embedded in it, (it expects $lb->insert() instead), so its scrolling code does not react to the Checkbuttons you are adding. I played with it several ways, and looked at the Listbox.pm source code, and cannot see how to make this work. I could be completely wrong, though.

The code below "works"; it scrolls, it looks like what Flame asked for, and each button tracks its input separately. There may be a simpler way, though.

#!/usr/bin/perl -W use warnings 'all'; use strict; use Tk::Pane; my $mw = Tk::MainWindow->new(); my $pane = $mw->Scrolled( 'Pane', -scrollbars => 'oe' )->pack( -expand => 'yes', -fill => 'both', # "-fill => 'y'" works, too ); my @list; for my $text ('A' .. 'Z') { my $value; $pane->Checkbutton( -anchor => 'w', -text => $text, -variable => \$value, )->pack( -side => 'top', -fill => 'x', ); push @list, \$value; } Tk::MainLoop(); printf "%s\n", $$_||0 foreach @list;

Replies are listed 'Best First'.
Re: Re: Tk List of Checkboxes?
by Flame (Deacon) on Jun 09, 2002 at 23:02 UTC
    Well, we're getting closer, I should probably expand on the goals for this though:

    Basically, I want to have the list one one side, and then a large 60x5 text field, a 60x1 text field and another list on the other side. As the user selects an item from the list on the left, I want to clear the elements on the right, and fill them with data pertaining to the object.

    Basically, the list is a list of options (hence, the checkboxes) but I'm building it to be expandable as I don't know how large the boxes could get in the long run. The other fields describe the options and their requirements.

    Hope this explains my question a little better. If anyone can offer an alternative, I'd be happy to hear it.



    "Weird things happen, get used to it."

    Flame ~ Lead Programmer: GMS