Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Perl:TK - standard output to text widget

by bbfu (Curate)
on Feb 27, 2004 at 21:25 UTC ( #332392=note: print w/replies, xml ) Need Help??

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"; }

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.

      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.

      Black flowers blossom
      Fearless on my breath

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://332392]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2016-10-21 17:07 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (289 votes). Check out past polls.