in reply to Tk::Text and buffering, I think

First of all, in Tk (or any gui program) using "sleep" will block the gui, so it's a "no-no". But to show you how to make it work ,in terms of your question, you need to set $|=1 and update your text widget after each print. Like:
#!/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__
But here is probably a better way, without using sleep. The reason is that a repeat loop, lets the Tk event loop proceed, and respond to the gui, while sleep will block everything until it is done.
#!/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"; }

However, you don't say what you are ultimately trying to do, and tie'ing STDOUT in Tk is not done very often, because there are usually better ways to accomplish it, like printing directly to the text box. What kind of program are you trying to make?


I'm not really a human, but I play one on earth. flash japh