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;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.