#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new; my $mainFrame = $mw->Frame()->pack(-side=>'top'); my $tx; # reuse global to prevent memory gains rebuild(); #setup first use # script is called, runs, outputs to Scrolled above, user # chooses new option and sub clear() is called: my $button = $mw->Button(-text=> 'Clear', -command => \&clear )->pack(); my $button1 = $mw->Button(-text=> 'Rebuild', -command => \&rebuild )->pack(); MainLoop; sub clear{ #$mainFrame ->destroy(); # don't, causes screen jitter $tx->packForget; # $tx ->pack('forget'); #wrong usage #clean out a top level # my @w = $tl->packSlaves; # foreach (@w) { $_->packForget; } } sub rebuild{ $tx = $mainFrame->Scrolled(qw/Text -font normal -width 73 -height 15 -wrap word -scrollbars e/); $tx->pack; tie *STDOUT, 'Tk::Text', $tx; print "foobar!".time."\n"; }