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


In reply to Re: Tk::Table cell select/deselect by Anonymous Monk
in thread Tk::Table cell select/deselect by amkkmkalk

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.