Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

perl/Tk and realtime update of output

by tcf03 (Deacon)
on Nov 09, 2005 at 16:53 UTC ( [id://507133]=perlquestion: print w/replies, xml ) Need Help??

tcf03 has asked for the wisdom of the Perl Monks concerning the following question:

I have the following code which pings some wireless access points. Im still writing it but Im looking for a way to update the text as each access point is pinged instead of after its done pinging them all. Any help is appreciated.
#!/usr/bin/perl use Net::Ping; use Tk; use Tk::Dialog; my $mw; my $shift; my $port; my @Addr=( 1 ... 55 ); my $statbar; $mw = MainWindow->new; $mw->title("AP ping"); $mw->geometry("203x595"); $mw->Label(-text => 'Choose Access Point to Ping')->place(-x => 5, -y +=> 5); $statBar = $mw->Label(-text => '', -font => [-family => 'Lucida Console +', -size => 8], -width => 28, -relief => 'groove')->place(-x => 0, - +y => 575); $mw->Button(-text => "Get Status", -relief => 'groove', -command => sub { $statBar->configure(-text => "pinging $h +ost"); if ( $host eq "All" ) { \&mstat($_) for +( 1 .. scalar(@Addr)) } else { \&mstat($host); } })->place(-x => + 60, -y => 70); $mw->Button(-text => "Exit", -relief => 'groove', -command => sub { exit })->place(-x => 172, -y => 70); my $tagOM = $mw->Optionmenu(-variable => \$host, -options => [ '', 'All', @Addr ], -width => 25, -relief => 'groove', -command => sub {})->place(-x => 5, -y => 30 +); my $statLog = $mw->Scrolled("Text", -scrollbars => 'e', -height => 30, + width=> 25)->place(-x => 0, -y => 130); MainLoop; ############# sub mstat ############# { $ap = shift; my $host = sprintf ("192.9.210.1%02d", $ap); my $p = Net::Ping->new(); if ( $p->ping($host)) { $statLog->insert('end', "AP $host is up\n"); #$statBar->configure(-text => "pinging $host is up"); } else { $statLog->insert('end', "AP $host is down\n"); #$statBar->configure(-text => "AP $host is down") } $p->close(); }

Ted
--
"That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved."
  --Ralph Waldo Emerson

Replies are listed 'Best First'.
Re: perl/Tk and realtime update of output
by gri6507 (Deacon) on Nov 09, 2005 at 16:57 UTC
    do a $mw->update() when you want to update your contents.
Re: perl/Tk and realtime update of output
by bageler (Hermit) on Nov 09, 2005 at 18:06 UTC
    set a $mw->repeat() if you want it to be recurring, like a status monitor:
    $mw->repeat( 2000 => sub { doPings(); updateTextFields(); $mw->update(); } );

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://507133]
Approved by BrowserUk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-19 16:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found