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