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;

In reply to Re: Tk List of Checkboxes? by Util
in thread Tk List of Checkboxes? by Flame

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.