siffland has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to learn tk so i am writing a simple script to ping hosts and make their names red if they are down and green if they are up. The script works fine except I cannot figure out how to make it refresh the screen. Currently the timer reruns the main subroutine and prints the output below the current output, i would just like it to update what is already there. I tried ->update as you can see on line 35 (it is commented out now) but that did not work. Any help would be appreicated, tk seems pretty cool and i would like to learn it.
#!/usr/bin/perl use strict; use warnings; use Net::Ping; use Tk; my @host_array = qw(server1 server2 server3 server4); my $window = MainWindow->new(); $window->minsize( qw(250 250)); $window->title("Server Status"); $window->configure (-background => 'grey'); my $top = $window->Frame(-background => 'grey',)->pack(-side=>'top',-f +ill=>'x'); #$window->Button(-text => "Refresh", -command => \&pinghost )->pack; my $timer = $window->repeat(2000,\&pinghost); $window->Button(-text => "Quit", -command => \&Quit )->pack; &pinghost; MainLoop(); ######################################################### sub pinghost{ foreach my $host (@host_array) { my $color = ("green"); my $p = Net::Ping->new("icmp"); $color = ("red") unless $p->ping($host, 2); $p->close(); my $t1 = $top->Label(-text=>"$host",-background => "$color")->pack +(); } #$window->update; } sub Quit{ exit; }
Thanks, Sean
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: TK refresh widgit data
by AnomalousMonk (Archbishop) on Jan 22, 2010 at 18:14 UTC | |
|
Re: TK refresh widgit data
by zentara (Cardinal) on Jan 22, 2010 at 19:05 UTC |