There are alot of ways to do this, and I'll bet if you search groups.google.com, you will find solutions.

As far as green and red indicators go, you can use just about any widget you want, and $widget->configure(-bg =>'green') and (red) at the appropraite times. The label is probably the smallest widget (as far as code size goes), but the CheckButton would be easy too, as it would let you label it too.

You will need to use a Tk::after or Tk::repeat to run your ps-test after a delay. But you can run it thru system, or check out Tk::ExecuteCommand.

#!/usr/bin/perl use Tk; use strict; use Tk::ExecuteCommand; my $mw = MainWindow->new; my $ec = $mw->ExecuteCommand( -command => '', -entryWidth => 50, -height => 10, -label => '', -text => 'Execute', )->pack; $ec->configure(-command => 'ls -la'); $ec->execute_command; $ec->bell; $ec->update; MainLoop;
As far as changing changing colors go, here is the general idea.
#!/usr/bin/perl use Tk; use strict; use constant BUTTON_WIDTH => 20; my $mw = new MainWindow(title => "demo"); my $button = $mw->Button(text => "color", width => BUTTON_WIDTH) ->pack; $mw->Button(text => "red", width => BUTTON_WIDTH, command => sub {change_color($button, "red")}) ->pack; $mw->Button(text => "green", width => BUTTON_WIDTH, command => sub {change_color($button, "green")}) ->pack; MainLoop; sub change_color { my ($widget, $color) = @_; $widget->configure(background => $color); }

And here is a neat little method for making an indicator.

#!/usr/bin/perl use Tk; use strict; my $mw = MainWindow->new; my @color = qw/red lightgray/; my $bits = pack("b8"x8, "...11...", "..1111..", ".111111.", "11111111", "11111111", ".111111.", "..1111..", "...11...",); $mw->DefineBitmap('indicator' => 8,8, $bits); my $label = $mw->Label(-bitmap=>'indicator', -fg=>'red')->pack; $mw->repeat(500,sub{$label->configure( -fg=>$color[0]); @color=reverse(@color); }); MainLoop;

I'm not really a human, but I play one on earth. flash japh

edited: Sun Apr 4 04:39:00 2004 by jeffa - added readmore


In reply to Re: Tk process monitoring by zentara
in thread Tk process monitoring by K_M_McMahon

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.