#!/usr/bin/perl 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()->pack; my $new_row = int rand 4; my $new_col = int rand 5; upd_table($new_row,$new_col); $but1->Button( -text => 'update', -command => sub { $new_row = int rand 4; $new_col = int rand 5; upd_table( $new_row,$new_col) }, )->pack(); MainLoop(); exit; sub upd_table { $table->packForget(); my ($rowin,$colin) = @_; $table = $lower->Table(-rows => $rowin, -columns => $colin)->pack; foreach my $row ( 0 .. $rowin-1 ) { foreach my $col ( 0 .. $colin ) { my $x = int rand 10; my $cell = $table->Entry( -width => 4, -text => $x ); $table->put( $row, $col, $cell ); } } }