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