in reply to Tk::Table cell select/deselect

One way

#!/usr/bin/perl -- ## ## 2014-06-09-12:49:11 ## ## ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr +-ce -nibc -i=4 -pt=0 "-nsak=*" #!/usr/bin/perl -- use strict; use warnings; use Tk; use Tk::Table; Main( @ARGV ); exit( 0 ); sub Santeria { my( $w ) = @_; #~ my( $w , $table ) = @_; my $table = $w->parent; $_->configure( -background => 'white' ) for $table->children; my( $row, $col ) = $table->Posn( $w ); print "row=$row, col=$col\n"; $w->configure( -background => 'grey' ); } ## end sub Santeria sub Main { my $mw = MainWindow->new; my $table = $mw->Table->pack; for my $iy ( 0 .. 5 ){ for my $ix ( 0 .. 5 ) { $table->put( $ix, $iy, "x($ix),y($iy)" ); } } #~ $table->bind( 'Tk::Label', '<1>', [ \&Santeria, $table ] ); $table->bind( 'Tk::Label', '<1>', \&Santeria ); #~ use Tk::WidgetDump; $mw->WidgetDump; MainLoop; } ## end sub Main __END__

You could also iterate in other Tk::Table ways, maybe even on $table->{Rows}

Another way, keep track of the selected widget, since it belongs to $table

my $last = $table->{last_selected}; $last and $last->configure( -background => 'white' ); $w->configure( -background => 'grey' ); $table->{last_selected} = $w;

I know what you're thinking, if you're going to do that, you should subclass Tk::Table, and add a destructor where you clean up these extra keys... :D

Replies are listed 'Best First'.
Re^2: Tk::Table cell select/deselect
by amkkmkalk (Novice) on Jun 09, 2014 at 21:42 UTC

    Thank You, excellent solution, I appreciate it and wish I would have been able to get it there. I will be able to adapt either of your suggestions for my needs. Thanks again.