in reply to Non editable cells in Tk::TableMatrix

Here is how I would do it using tags. Tags are kind of tricky ( notice I needed the tagRaise to make the example below work). But this is much faster, because it dosn't make all those Label and Button widgets. Tags are used in the Canvas, Text, and a few other widgets, they are very powerful if used correctly. You should read the perldoc Tk::TableMatrix section on tags, and play with them. To really make them work, you usually need to read the tags on the row,column or cell, then delete out a tag temporarily, then put it back, etc,etc....it can be a real juggling act, but it is simple once you get a scheme going.
#!/usr/bin/perl use Tk; use Tk::TableMatrix; use strict; use warnings; my $arrayVar = {}; print "Filling Array...\n"; my ($rows,$cols) = (6, 500); foreach my $row (1..$rows){ $arrayVar->{"$row,0"} = "$row"; } foreach my $col (1..$cols){ $arrayVar->{"0,$col"} = "$col"; } my $mw = MainWindow->new; my $table = $mw->Scrolled( "TableMatrix", -resizeborders => 'none', -titlecols => 1, -rows => 7, -colstretchmode => 'all', -cols => 501, -cache => 1, -scrollbars => "osoe", -variable => $arrayVar, )->pack( -expand => 1, -fill => 'both'); $table->tagConfigure('dis', -state => 'disabled', -bg => 'white'); $table->tagConfigure('act', -state => 'normal', -bg => 'lightyellow'); foreach my $col(1..500) { foreach my $row(1..7) { # $table->set("$row,$col","$row-$col"); $table->tagCell('dis',"$row,$col"); if($row == 4){ $table->set("$row,$col",'Active'); $table->tagCell('act',"$row,$col"); } } } my $button = $mw->Button(-text=>'Activate Row 2', -command=>sub{ # $table->tagDelete('dis', 2); $table->tagRow('act', 2); $table->tagRaise('act'); })->pack(); MainLoop; __END__

I'm not really a human, but I play one on earth Remember How Lucky You Are

Replies are listed 'Best First'.
Re^2: Non editable cells in Tk::TableMatrix
by ravishi (Acolyte) on Oct 03, 2008 at 20:55 UTC
    As always zentara, you've come to my rescue. I'm going to have to learn more about tags now. Thanks for the coding format suggestions as well.
Re^2: Non editable cells in Tk::TableMatrix
by NateTut (Deacon) on Jun 23, 2011 at 20:06 UTC
    Has anyone ever used row tags with TableMatrix?
      Row tags are pretty straightforward, and work almost like regular tags, except they affect all columns. What sort of thing are you trying to accomplish? Here is a simple example.
      #!/usr/bin/perl 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) ; } my $t = $mw->Scrolled('TableMatrix', -rows => $rows, -cols => $cols, -width => 6, -height => 6, -titlerows => 1, -titlecols => 1, -variable => $arrayVar, -coltagcommand => \&colSub, -colstretchmode => 'last', -rowstretchmode => 'last', -selectmode => 'extended', -selecttitles => 0, -drawmode => 'slow', -scrollbars=>'se' ); $mw->Button(-text => "Update", -command => \&update_table) ->pack(-side => 'bottom',-anchor => 'w'); # hideous Color definitions here: $t->tagConfigure('active', -bg => 'white', -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); sub update_table { print "1\n"; $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.
      Old Perl Programmer Haiku ................... flash japh
        Thank you. I was able to get it figured out by combining a couple of your samples. Basically I just want to gang all the cells together. It's really dumbing down a lot of the capabilities of TableMatrix, but I am working with spreadsheet data & I like the "cellular" look of TableMatrix. This is my first production Tk project and I've worked with it enough now that it is starting to make sense to me. Give a monkey a typewriter and eventually he will write War and Peace.