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.


In reply to Tk::Table clear creates unwanted boxes by toolic

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.