I still don't have an answer as to what is going wrong, but I did take a few moments and tried to move my second example even closer to what I'm guessing you were going for. Admittedly, I left out a column, but didn't have a good idea what you were doing there, so I ignored it.

Since this third example is a little closer to what I think you were going for, maybe it will help. After thinking more about the snippet you provided, I do have a few questions/recommendations:

  1. Why is there a Checkbutton and a Submit Button on each row? I would have thought that you could get by with one or the other. I'm guessing that the Submit button will cause another window with editable text fields to appear, populated with the data for a row. It seems like an unnecessary extra step to have to select the Checkbutton, too.

  2. Avoid Tk::Table - Not because it's a bad widget -- it's Ok, and it does work, but it's an efficient way to display tabular data, and there are other arguably better options available such as HList or TableMatrix. For large data sets, Tk::Table will consume far more memory than say: HList or TableMatrix.

  3. You don't have to maintain a reference to each Checkbutton. Especially since you are using Tk::Table. You can access any widget stored inside it so long as you know it's row and column -- the same can be done with the grid geometry manager

use Tk; use Tk::Table; use strict; use Class::Struct; struct Bill => [ amountDue => '$', amountPaid => '$', dateDue => '$', datePaid => '$', name => '$', ]; ## Dummy Data for Display my @unpaidBills = ( createBill("GrandFather", "10.00"), createBill("Rob", "100.00"), createBill("Koosemose", "250.00"), createBill("Mikasue", "500.00") ); my $mw = MainWindow->new; my $table = $mw->Table( -scrollbars => '', -fixedrows => 1, -columns => 7, -rows => 5 )->pack(qw/-expand 1 -fill both/); ## Populate Headers my $hdrCol = 1; foreach my $hdr (qw/Name Due DateDue Paid DatePaid/) { $table->put(0, $hdrCol, $hdr); $table->get(0, $hdrCol)->configure(-width => 12); $hdrCol++; } ## Populate Rows my @cbValues; my $row = 1; foreach my $bill (@unpaidBills) { populateRow($table, $row++, $bill); } MainLoop; ## Convenience Routine for creating unpaid Bills sub createBill { my ($name, $owed) = @_; return Bill->new( name => $name, amountDue => $owed, amountPaid => 0, dateDue => "2 OCT 2006", datePaid => ""); } ## Convenience Routine for creating a row sub populateRow { my ($table, $row, $bill) = @_; my $col = 0; my $index = $row-1; $table->put($row, $col++, $table->Checkbutton( -variable => \$cbValues[$index])); $table->put($row, $col++, $bill->name); $table->put($row, $col++, $bill->amountDue); $table->put($row, $col++, $bill->dateDue); $table->put($row, $col++, $bill->amountPaid); $table->put($row, $col++, $bill->datePaid); $table->put($row, $col, $table->Button( -text => 'Submit', -command => sub { if ($cbValues[$index] == 1) { print "$index selected\n"; } else { print "$index not selected\n"; } })); ## Format each cell to create speadsheet- ## like effect foreach my $c (0 .. 5) { my $widget = $table->get($row, $c); $widget->configure( -anchor => 'w', -relief => 'groove' ); } }

In reply to Re: Array of TK::Checkbuttons not acting appropriately by rcseege
in thread Array of TK::Checkbuttons not acting appropriately by mikasue

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.