Hi Monks,
Most simple perl programs are scripts run at the command line. To make them look a little more professional I'm writing a simple "standard gui" module with TK so that the scripts run in a nice gui style window. Its mostly written. But I have one problem I haven't been able to solve ...
Basically I want to capture STDOUT to a text-like widget. Now STDOUT is a stream, directed somewhere, for example to the terminal. I want to direct this to my text widget. I'm guessing I need to create a reference type glog of the STDOUT to my text-widget? Or open a filehandle to it or a pipe? Or call a subroutine in a loop that reads the STDOUT and appends it to the text-widget? As you can tell I'm not sure. Help?!
The bare guts of the code is below.
Thoughts/comments/suggestions?
Thanks
Dean
use Tk;
use Tk::Pane;
my $mw = MainWindow->new (-title => 'sgui');
$mw->resizable('false','true');
my $run = $mw -> Button(-text => 'Run!',
-width => 27,
-command => [\&that]
);
my $enter = $mw->Label(-text => "\nOutput");
my $pane = $mw->Scrolled("Pane",
Name => 'fred',
-scrollbars => 'osoe',
-sticky => 'we',
-width => 540,
-height => 580
);
my $text = $pane->Text(-width => 75, -height => 40);
my $quitButton = $mw->Button ( -text => 'Quit',
-width => 27,
-command => \&quit);
$enter->pack;
$pane->Frame;
$pane->pack;
$text->pack;
$text->insert('end', \*STDOUT);
$quitButton->pack;
MainLoop;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.