ldln has asked for the wisdom of the Perl Monks concerning the following question:

I've been using Tk::TableMatrix::Spreadsheet module for several years and I like it allot, but I've always been annoyed that I can't "freeze" top row. It looks terrible when top row is resized to ~1px (almost hidden). So, is there a way to "freeze" top row in a Tk::TableMatrix widget, so that it can't be scrolled resized vertically (while still allowing other rows to be scrolled resized vertically)?

I guess we have to dig into internals of TableMatrix module to accomplish this? Anyone got experience doing this?

Replies are listed 'Best First'.
Re: Freeze top row in Tk::TableMatrix
by zentara (Cardinal) on Jan 17, 2009 at 15:41 UTC
    Hi, here is something quick that does it. A combination of stretchmode settings and min size height for the window seems to do it. You can play around with other stretchmode settings, and setting the min height you want.
    #!/usr/bin/perl use Tk; use Tk::TableMatrix; my $mw = MainWindow->new; $mw->minsize(600, 125); # height, width 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"} = 2*$row + 3*$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 => 10, -height => 10, -titlerows => 1, -titlecols => 1, -variable => $arrayVar, -coltagcommand => \&colSub, -browsecommand => \&brscmd, -colstretchmode => 'all', -rowstretchmode => 'all', -selectmode => 'extended', -selecttitles => 0, -drawmode => 'slow', -scrollbars=>'se' ); #---------------------------------- #HERE IS WHERE I TRY TO USE BUTTONS #---------------------------------- my $buttonTest = $mw->Button(-text => "test")->pack(-expand=>1,-fill=> +'both'); #$t->set("3,3",-window=> $buttonTest); #print $t->configure(window,"3,3"),"\n"; $t->windowConfigure("3,3", -window => $buttonTest); #my $textcontainer = $t->createWindow(# # 3,3 # default anchor is center # -window => $buttonTest, # ); #---------------------------------- $mw->Button(-text => "Update", -command => \&update_table) ->pack(-side => 'bottom',-anchor => 'w'); $mw->Button(-text => "Disable", -command => \&dis_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', -bg => 'black'); $t->pack(-expand => 1, -fill => 'both'); $t->focus; Tk::MainLoop; sub update_table { print "1\n"; $t->tagCell('dis', '1,1' ); $t->tagRaise('dis', 'OddCol'); # only needed if coltagcommand used $t->activate('2,2'); $t->tagRow('active',3); # $t->configure(-padx =>( $t->cget(-padx))); # a trick needed sometimes to update } sub brscmd { my ($previous_index, $actual_index) = @_; my ($row, $col) = split ',', $actual_index; print "r$row c$col\n"; } sub dis_table{ print "2\n"; foreach my $col (1..4){ if ($arrayVar->{"6,$col"} >= 1) { print "col->$col\n"; $t->tagCell('dis',"7,$col"); $t->tagCell('dis',"8,$col"); $t->tagCell('dis',"9,$col"); } } $t->tagRaise('dis', 'OddCol'); # only needed if coltagcommand used }

    I'm not really a human, but I play one on earth Remember How Lucky You Are
      Hm, I didn't quite understand what this code did regarding disabling top row vertical resize (or any row for that matter). As far as I can see, all rows still can be resized?!
        From your limited description of the problem in the original node, I thought you were talking about how the header row of the table can get squished down to non-visible upon resizing the whole window. My script stopped the crushing, so the header row remained totally readable, while still allowing you to scroll the data. Otherwise, explain better what you want to see. The widget is difficult to deal with, and you may want to go to a better widget giving you more control. The only one in Tk is the canvas, and you can setup a scrolling table easily in it.

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