senthilkumar has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, I am a newbie to perl-tk. I have a requirement to display all the print statements that are generated by perl script into perl-tk GUI. Example::
Now executing parser code... generated nodes after parsing ... sending the nodes ...
like above. Is there any possibility to do this ??. Any help is appreciated..

Replies are listed 'Best First'.
Re: Displaying print statements in Tk
by shevek (Beadle) on Oct 26, 2010 at 12:29 UTC
    Hello,

    Please search for this "Perl:TK - standard output to text widget". This is a question that was answered in 2004 on perlmonks. Search is a great tool and friend.

    Here is the link: http://www.perlmonks.org/?node_id=332324

    Please try and code an example after reading the above node. If you still can't get it to work then post with the code. I am sure we will be able to help you a lot more at that point.

Re: Displaying print statements in Tk
by ww (Archbishop) on Oct 26, 2010 at 12:32 UTC
Re: Displaying print statements in Tk
by Marshall (Canon) on Oct 26, 2010 at 13:14 UTC
    If you are the one doing the "printing" and that's what it sounds like:
    # make a frame, say frame_text, then create a text # widget: my $text = $frame_text->Scrolled ('Text', -scrollbars=>'se', ) ->pack(-expand=>1, -fill=>'both'); #append lines with: $text->insert ('end', $_); #delete all lines $text->delete("1.0", 'end');
    Multi-threads and re-directing output from other program is more complex, but if all you need is that your "command line output" gets put into the GUI, just follow the above.
Re: Displaying print statements in Tk
by kcott (Archbishop) on Oct 26, 2010 at 20:36 UTC

    As you're new to Perl/Tk, here's some resources you'll probably find useful:

    • Documentation for Tk Modules.
    • Documentation for User Contributed Tk Modules.
    • The book Mastering Perl/Tklink removed - see below is online.
    • The widget demo which comes with the Tk distribution: just type widget on the commandline.

    Update:

    I had included a link to an online version of Mastering Perl/Tk. It was pointed out to me that this was a pirated copy so the link has been removed. This book is published by O'Reilly. They have a page with details of Mastering Perl/Tk - this includes a link to Safari Books Online which you can follow from their site.

    -- Ken