in reply to Freeze top row in Tk::TableMatrix

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

Replies are listed 'Best First'.
Re^2: Freeze top row in Tk::TableMatrix
by ldln (Pilgrim) on Jan 17, 2009 at 17:50 UTC
    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
        Sorry, my mistake for beeing unclear in my description of the problem. I will try again.

        I have a Tk::TableMatrix::SpreadSheet table which I fill with data. In columns in top row I have button widgets, which when clicked sorts data in in the table and then repopulates it with sorted data.
        We can adjust size of cells by "clicking and dragging" on table borders. What I would like is the top row to maintain the same height all the time - that is make it impossible to resize it vertically.

        I guess we have to poke into the Spreadsheet.pm (or TableMatrix.pm) file and see how it operates?