A package, BMORROW::Tie::TkWatch, to give "a basically command-line program a simple GUI". Reproduced here with the author's consent.

The module

package BMORROW::Tie::TkWatch; use warnings; use strict; our @EXPORT_OK = qw/Run Dialog Update/; use base qw/Exporter/; use Tk; use Tk::Dialog; use Scalar::Util qw/openhandle/; my %TK; $TK{mw} = Tk::MainWindow->new( -title => 'Perl', ); $TK{font} = $TK{mw}->Font( -family => 'Bitstream Vera Sans Mono', -size => 10, ); $TK{out} = $TK{mw}->Scrolled( ROText => -font => $TK{font}, -width => 80, -height => 35, -scrollbars => 'osoe', )->pack( -fill => 'both', -expand => 'y', ); $TK{out}->tag(configure => out => -foreground => 'black'); $TK{out}->tag(configure => err => -foreground => 'red'); $TK{out}->focus; sub TIEHANDLE { my $c = shift; return bless \@_, $c; } sub PRINT { my $s = shift; my ($o, $t, $h) = @$s; my $txt = do { no warnings 'uninitialized'; (join $,, @_) . $\ }; openhandle $h and print $h $txt; $o->insert(end => $txt, $t); $o->see('end'); $o->update; } tie *STDOUT, __PACKAGE__, $TK{out}, 'out'; open my $OERR, '>&', \*STDERR; tie *STDERR, __PACKAGE__, $TK{out}, 'err', $OERR; sub Run (&$) { my $sub = shift; $TK{mw}->configure(-title => shift); $TK{mw}->after(0, $sub); Tk::MainLoop; } sub Dialog { my $ans = $TK{mw}->Dialog(@_)->Show(); $TK{mw}->update; return $ans; } sub Update { $TK{mw}->update; } sub Tk::Error { my ($mw, $err) = @_; print STDERR $err; } 1; __END__ =head1 AUTHOR, WARRANTY, COPYRIGHT, & LICENCE INFO Copyright 2007 Ben Morrow This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.5 or, at your option, any later version of Perl 5 you may have available. =cut

Usage

#!/usr/bin/perl use BMORROW::Tie::TkWatch qw/Run/; Run { print "Hello world!\n"; warn "Houston, we have a problem"; } 'My Perl App'; __END__

More Info

This was recently posted on clpmisc by Ben Morrow. (Available from Google Groups too.) I asked for permission to reproduce it here and he agreed. I only added the copyright notice as per the author's request. See the original thread linked above for more info.

In reply to CLI program to simple GUI wrapper by blazar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.