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

Dear Monks, How to increase the size of column in Perl Tk::Table?

Replies are listed 'Best First'.
Re: Increase The coloumn size in Perl Tk?
by choroba (Cardinal) on May 10, 2011 at 11:54 UTC
    use Tk; use Tk::Table; $t = MainWindow->new(-title=>"tablesize") ->Table(rows => 5, columns => 5)->pack; for $x (0 .. 4) { for $y (0 .. 4) { $t->put($x, $y, "$x:$y"); } }; $t->parent->Button(-text =>"+", -command => sub { $x=$t->get(2,3); $x->configure(-width => $x->cget("-width") + 1) } )->pack; MainLoop;

      I ran your code and it works great. I tried to add a '-' button but can't get it to work. Any ideas?

      use Tk; use Tk::Table; $t = MainWindow->new(-title=>"tablesize") ->Table(rows => 5, columns => 5)->pack; for $x (0 .. 4) { for $y (0 .. 4) { $t->put($x, $y, "$x:$y"); } }; $t->parent->Button(-text =>"+", -command => sub { $x1=$t->get(2,2); $x1->configure(-width => $x1->cget("-width") + +1); } )->pack; $t->parent->Button(-text =>" - ", -command => sub { $x1=$t->get(2,2); $x1->configure(-width => $x1->cget("-width") - +1); } )->pack; MainLoop;
Re: Increase The coloumn size in Perl Tk?
by zentara (Cardinal) on May 10, 2011 at 14:46 UTC
    The Tk::Table is not a very feature rich widget. I don't think it was designed for expanding/shrinking individual cells, without causing a glitch somewhere else, like improper layout of whatever you were to put in the cell.

    You may have luck, but maybe you should look at TableMatrix or TableMatrix::Spreadsheet.

    For example:

    #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::TableMatrix; my $top = MainWindow->new; my $arrayVar = {}; print "Filling Array...\n"; my ($rows,$cols) = (400, 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 $label = $top->Label(-text => "TableMatrix v2 Example"); my $t = $top->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' ); my $button = $top->Button( -text => "Exit", -command => sub{ $top->destroy}); # hideous Color definitions here: $t->tagConfigure('OddCol', -bg => 'brown', -fg => 'pink'); $t->tagConfigure('title', -bg => 'red', -fg => 'blue', -relief => 'sun +ken'); $t->tagConfigure('dis', -state => 'disabled'); my $i = -1; my $first = $t->cget(-colorigin); my $anchor; foreach $anchor( qw/ n s e w nw ne sw se c /){ $t->tagConfigure($anchor, -anchor => $anchor); $t->tagRow($anchor, ++$i); $t->set( "$i,$first",$anchor); } $top->fontCreate('courier', -family => 'courier', -size => 10); $t->tagConfigure('s', -font => 'courier', -justify => 'center'); $t->colWidth( -2 => 8, -1 => 9, 0=> 12, 4=> 14); $label->pack( -expand => 1, -fill => 'both'); $t->pack(-expand => 1, -fill => 'both'); $button->pack(-expand => 1, -fill => 'x'); Tk::MainLoop;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh