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