taking into account my current level.

Well to help you understand a bit better, whenever you run something that can take time, and/or hang, like a ping, you need to separate that code from the gui eventloop code. This is usually done thru IPC, forking, or threads. That keeps the gui responsive.

So here is a simpler example of it. This code forks off the ping command, thru a piped open ( see "perldoc perlipc"), and then allows the tk eventloop to read the filehandle thru fileevent ( which is similar to C's select ). The problem with using Net::Ping is that it dosn't allow you direct access to the filehandles involved, like a piped open does. Then you need the hack workaround.

Here is a simpler version of using fileevent, for you to see the basics.

#!/usr/bin/perl -w use Tk; use strict; my $host = 'localhost'; my $mw = MainWindow->new; my $t = $mw->Scrolled("Text",-width => 80, -height => 25, -wrap => 'none')->pack(-expand => 1); my $button = $mw->Button(-text => 'Execute', -command => \&ping_test)->pack; MainLoop(); sub ping_test { open (PINGTEST, "ping $host 2>&1 |") or die "can't fork: $!"; $mw->fileevent(\*PINGTEST, 'readable', [\&fill_text_widget,$t]); $button->configure(-text => 'Stop', -command => sub{ print "Close Filehandle\n"; close PINGTEST;# or die "bad ping: $! S?"; print "All done!\n"; }); } sub fill_text_widget { my($widget) = @_; $_ = <PINGTEST>; $widget->insert('end', $_); $widget->yview('end'); }

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

In reply to Re^3: TK, insert and foreach by zentara
in thread TK, insert and foreach by papaismurf

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.