++

As Mr. Spock would say... fascinating. Much appreciated, Athanasius. Your modification works for me as well, even on an older version of Tk. That solves the problem for my original post.

The real reason I have the sub is that I also need the number of rows to vary each time I click the button. So, the OP was reduced too much. Thanks to your recommendation, my more realistic code below works also. I happen to know up front that the maximum number of rows is a constant (32):

use warnings; use strict; use Tk; use Tk::Table; my $mw = MainWindow->new(); my $upper = $mw->Frame()->pack(-side => 'top'); my $but1 = $upper->Frame()->pack(); my $lower = $mw->Frame()->pack(-side => 'bottom'); my $table = $lower->Table(-rows => 32, -columns => 5)->pack; upd_table(); $but1->Button( -text => 'update', -command => sub { upd_table() }, )->pack(); MainLoop(); exit; sub upd_table { $table->clear() if $table; my $r = 3 + int rand 3; foreach my $row ( 0 .. $r-1 ) { foreach my $col ( 0 .. 4 ) { my $x = int rand 10; my $cell = $table->Entry( -width => 4, -text => $x ); $table->put( $row, $col, $cell ); } } }

It would be helpful if another Monk could explain this behavior and suggest a better method.


In reply to Re^2: Tk::Table clear creates unwanted boxes by toolic
in thread 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.