in reply to Re^2: TK spread sheet color row
in thread TK spread sheet color row
yet I fail to find a way to color the row
I'm not really a human, but I play one on earth. ..... an animated JAPH
Hi, you can try
and here is a full working example. Press the Update button to see it work.$t->tagRow('active', $row);
#!/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"; ## 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) ; } 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, -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 => 'white', -fg => 'red', -relief => 's +unken'); $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); sub update_table { $t->tagCell('dis', '1,1' ); $t->activate('2,2'); $t->tagRow('active',3); # $t->configure(-padx =>( $t->cget(-padx))); # a trick needed sometimes to update }
I'm not really a human, but I play one on earth. ..... an animated JAPH
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: TK spread sheet color row
by aviw (Acolyte) on Jul 09, 2017 at 14:16 UTC | |
by zentara (Archbishop) on Jul 09, 2017 at 15:19 UTC | |
by aviw (Acolyte) on Jul 09, 2017 at 15:23 UTC | |
by zentara (Archbishop) on Jul 09, 2017 at 15:24 UTC | |
by aviw (Acolyte) on Jul 09, 2017 at 16:39 UTC |
In Section
Seekers of Perl Wisdom