toolic has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to use Tk::Table for the first time, but I get an unwanted empty box every time I clear the table.
When I first execute the code, everything looks as expected. I see the "update" button at the top of the window and a table with 3 rows and 5 columns below the button. The table is filled with random values (0-9).
When I click the "update" button for the 1st time, the table is updated with a new set of random values, as desired. However, a small empty box also appears between the "update" button and the table. Every subsequent click of the button adds another empty box. If I click the button 10 times, I end up with 10 empty boxes stacked vertically. This resizes the window and pushes the table further down. If I click enough times, the table disappears off the bottom of my screen. The clear method works, but I need to figure out how to prevent the empty boxes from appearing.
I adapted my code from this Perlmonks node: Re: Cursor position in Tk::Table
use warnings; use strict; use Tk; use Tk::Table; my $table; my $mw = MainWindow->new(); my $upper = $mw->Frame()->pack(-side => 'top'); my $but1 = $upper->Frame()->pack(); my $lower = $mw->Frame()->pack(-side => 'bottom'); upd_table(); $but1->Button( -text => 'update', -command => sub { upd_table() }, )->pack(); MainLoop(); exit; sub upd_table { $table->clear() if $table; $table = $lower->Table( -rows => 3, -columns => 5)->pack; foreach my $row ( 0 .. 2 ) { foreach my $col ( 0 .. 4 ) { my $x = int rand 10; my $cell = $table->Entry( -width => 4, -text => $x ); $table->put( $row, $col, $cell ); } } }
I'm using the latest version of Tk, just installed:
perl -MTk -le 'print $Tk::VERSION' 804.032
Can anyone else reproduce this? Did I describe the problem clearly? I don't see any relevant open bug reports. What am I doing wrong?
P.S. As a testament to the effectiveness of Super Search, this is the first time I've hit the "submit" button on SoPW (after more than 3000 posts). I've started composing SoPW posts several times, but SS has always given me the answer before I posted.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tk::Table clear creates unwanted boxes
by Athanasius (Archbishop) on Aug 05, 2014 at 15:42 UTC | |
by choroba (Cardinal) on Aug 05, 2014 at 16:23 UTC | |
by toolic (Bishop) on Aug 05, 2014 at 16:33 UTC | |
by Anonymous Monk on Aug 06, 2014 at 00:29 UTC | |
by toolic (Bishop) on Aug 05, 2014 at 16:25 UTC | |
by zentara (Cardinal) on Aug 05, 2014 at 17:05 UTC | |
by toolic (Bishop) on Aug 05, 2014 at 17:14 UTC |