#!/usr/bin/perl use warnings; use strict; use Tk; $|=1; my $mw = tkinit; # a frame in my Tk main window my $frame = $mw->Frame; # a text widget with attached scrollbars in my frame my $OutputText = $frame->Scrolled('Text', -height => '10', -width => '50', -scrollbars => 'osoe' ); # pack frame and text widget $frame->pack(qw/-side left -fill y/); $OutputText->pack(qw/-side bottom -fill both -expand 1/); # here I try to tie STDOUT to the text widget my $widget = $OutputText->Subwidget("text"); tie *STDOUT, ref $widget, $widget; $mw->Button(-text=>'start', -command => [\&start])->pack;; MainLoop; sub start{ for ( 1..10 ) { sleep 1; print "foo\n"; $OutputText->update; } } __END__ #### #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new(); my $tx = $mw->Text()->pack(); tie *STDOUT, 'Tk::Text', $tx; $mw->repeat(1000, \&tick); MainLoop; my $count; sub tick { ++$count; print "$count\n"; }