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

I was doing something with Tk::Table, and found this bug. If you run this code you will see:

use Tk; use Tk::Table; use strict; use warnings; my $mw = MainWindow->new; $mw->geometry("200x200"); my $table = $mw->Table(-rows => 9, -columns => 9, -fixedrows => 9, fix +edcolumns => 8)->pack; foreach my $row (0 .. 8) { foreach my $col (0 .. 8) { my $cell = $mw->Entry(-width => 1); $table->put($row, $col, $cell); } } MainLoop;

Tk::Table will try to display a north scrollbar for you. That's fine, I think it is because columns is greater than fixedcolumns. The problem is with the position the scrollbar is placed. It is not right over the table, but over on the right side.

The testing was done on windows xp with activestate perl 5.8.4.

Replies are listed 'Best First'.
Re: misplaced scroll bar with Tk::Table
by GrandFather (Saint) on Aug 12, 2005 at 06:41 UTC

    You need to create the cells using $table rather than $mw:

    my $cell = $table->Entry (-width => 1);

    Perl is Huffman encoded by design.

      Still there is a problem. The scrollbar is now at the top right corner, however it is a tiny one. The expectation is for the scrollbar to go across the entire width of the table.

      On the other hand, even with my original code, it is still a bug in Tk::Table. If what I did was wrong, Tk::Table should throw error or warning, not to accept it quietly and screw things up.

        What do you actually want to achieve? The sample code below may give a better feel for what is going on. Note that the columns are not fixed and that the width of the entries is enough that not all the columns are visible.

        The key point is that the scroll bars only scroll non-fixed columns.

        use Tk; use Tk::Table; use strict; use warnings; my $mw = MainWindow->new; $mw->geometry("200x200"); my $table = $mw->Table (-rows => 9, -columns => 9, -fixedrows => 9)->pack; foreach my $row (0 .. 8) { foreach my $col (0 .. 8) { my $cell = $table->Entry (-width => 4, -text => "$col, $row"); $table->put ($row, $col, $cell); } } MainLoop;

        Perl is Huffman encoded by design.
Re: misplaced scroll bar with Tk::Table
by zentara (Cardinal) on Aug 12, 2005 at 11:49 UTC
    Usually one uses the "Scrolled" method of creating a scrolled widget.
    #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Table; my $mw= tkinit; $mw->geometry("400x400+100+100"); my $table = $mw->Scrolled('Table', -rows => 20, -columns => 50, -fixedrows => 9, -scrollbars => 'osoe', -takefocus => 1)->pack; foreach my $row (0 .. 8) { foreach my $col (0 .. 8) { my $cell = $table->Entry ( -width => 4, -text => "$col, $row"); $table->put ($row, $col, $cell); } } MainLoop;

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