http://www.perlmonks.org?node_id=332392


in reply to Perl:TK - standard output to text widget

You can tie STDOUT to a Tk::Text object to have anything printed in perl appear in the text widget. This doesn't handle input, of course, nor does it work with any external programs you might call (for those, see the previous suggestions).

#!/usr/bin/winperl 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"; }

bbfu
Black flowers blossom
Fearless on my breath

Replies are listed 'Best First'.
Re: Re: Perl:TK - standard output to text widget
by crabbdean (Pilgrim) on Feb 28, 2004 at 09:12 UTC
    Man you are no less than a God!!! What a brilliant solution. Very clever. Something I didn't even consider. Works a treat. Now I just have to solve the other little myriad of problems and see if I can come up with a nice modular solution.

    Its getting closer bit by bit.

    Dean
      merlyn pointed out that this feature is undocumented. Thus, it might be subject to change, not 100% reliable, etc. I haven't personally used it much, so I can't vouch for its reliability, either. If you have to use it in production code, you should keep a good test suite that you can re-run after every update.

      bbfu
      Black flowers blossom
      Fearless on my breath