EDIT: I always get some idea after I post my question...

This is a better approach. Still not the right one, as it must be possible to set directly that color some way.

#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::TableMatrix; my $mw = MainWindow->new; my $arrayVar = {}; print "Filling Array...\n"; my ($rows,$cols) = (10, 10); foreach my $row (0..($rows-1)){ foreach my $col (0..($cols-1)){ $arrayVar->{"$row,$col"} = "$row,$col"; } } print "Creating Table...\n"; sub colSub{ my $col = shift; return "OddCol" if( $col > 0 && $col%2) ; } sub rowSub{ my $row = shift; return "Oddrow" if( $row > 0 && $row%2) ; } my $t = $mw->Scrolled('TableMatrix', -rows => $rows, -cols => $cols, -width => 6, -height => 6, -titlerows => 1, -titlecols => 1, -variable => $arrayVar, -coltagcommand => \&colSub, #-browsecommand => \&coloring, -colstretchmode => 'last', -rowtagcommand => \&rowSub, -rowstretchmode => 'last', -selectmode => 'extended', -selecttitles => 0, -drawmode => 'slow', -scrollbars=>'se', -relief => 'ridge', -selectmode => 'extended', -selecttype=>'row', ); $t->bind('<Button-1>', \&coloring); # Color definitions here: $t->tagConfigure('active', -bg => 'lightyellow', -fg => 'black'); $t->tagConfigure('nonactive', -bg => 'white', -fg => 'black'); $t->pack(-expand => 1, -fill => 'both'); $t->focus; $t->configure (-state=>'disabled'); Tk::MainLoop; my $selected = -1; my $prev_selected = -1; $t->bind('<Button-1>', \&coloring); sub coloring { my $t = shift; print "COLORING SELECTED ROW ($prev_selected = $selected)...\n"; my $event = $t->XEvent; $selected = $t->index('@'.$event->x.','.$event->y, 'row'); $t->tagRow('nonactive',$prev_selected) if (defined $prev_selected + && $prev_selected != -1); $t->tagRow('active',$selected) if (defined $selected); $prev_selected = $selected; }

In reply to Re: Tk Tablematrix set color of selected row by Takamoto
in thread Tk Tablematrix set color of selected row by Takamoto

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.