Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Tk Tablematrix set color of selected row

by Takamoto (Monk)
on Apr 06, 2020 at 17:15 UTC ( [id://11115139]=note: print w/replies, xml ) Need Help??


in reply to Tk Tablematrix set color of selected row

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11115139]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-19 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found