#.. remove the headers same as yours so msg will be shorter. 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"; ## Test out the use of a callback to define tags on rows and columns sub colSub{ my $col = shift; return "OddCol" if( $col > 0 && $col%2) ; } my $t = $mw->Scrolled('TableMatrix', -rows => $rows, -cols => $cols, -width => 6, -height => 6, -titlerows => 1, -titlecols => 1, -variable => $arrayVar, -coltagcommand => \&colSub, -colstretchmode => 'last', -rowtagcommand => \&rowSub, -rowstretchmode => 'last', -selectmode => 'extended', -selecttitles => 0, -drawmode => 'slow', -scrollbars=>'se' ); $mw->Button(-text => "Update", -command => \&update_table) ->pack(-side => 'bottom',-anchor => 'w'); # Color definitions here: $t->tagConfigure('active', -bg => 'blue', -fg => 'red', -relief => 'sunken'); $t->tagConfigure('OddCol', -bg => 'lightyellow', -fg => 'black'); $t->tagConfigure('title', -bg => 'lightblue', -fg => 'black', -relief => 'sunken'); $t->tagConfigure('dis', -state => 'disabled'); $t->pack(-expand => 1, -fill => 'both'); $t->focus; Tk::MainLoop; # $t->tagConfigure($anchor, -anchor => $anchor); # $t->tagRow($anchor, ++$i); # $t->set( "$i,$first",$anchor); my $selected = -1; my $prev_selected = -1; sub update_table { #$t->tagCell('dis', '1,1' ); # REMOVED #$t->activate('2,2'); # REMOVED warn("\n\n\nprev_selected:'$prev_selected' , selected:'$selected'"); # ADDED $t->tagRow('active',$selected) if ($selected != -1); # ADDED $t->tagRow('OddCol',$prev_selected) if (defined $prev_selected && $prev_selected != -1); # ADDED $prev_selected = $selected; # ADDED warn("\n\n\npost updated prev_selected:'$prev_selected' , selected:'$selected'"); # $t->configure(-padx =>( $t->cget(-padx))); # a trick needed sometimes to update } sub rowSub{ my $row = shift; $selected = $row; # ADDED warn ("\n\nrowSub - row: $row"); # ADDED return "Oddrow" if( $row > 0 && $row%2) ; }