in reply to Array of TK::Checkbuttons not acting appropriately

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' ); } }