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

Hello,everyone:

<<How to be in the following code rolling display data (real time)?

use Tk; my $mw = new MainWindow; # Main Window my $frm_name = $mw -> Frame(); my $lab = $frm_name -> Label(-text=>"IP:"); my $ent = $frm_name -> Entry(); my $but = $mw -> Button(-text=>"Push Me", -command =>\&push_button); my $textarea = $mw -> Frame(); #Creating Another Frame my $txt = $textarea -> Text(-width=>40, -height=>10); my $srl_y = $textarea -> Scrollbar(-orient=>'v',-command=>[yview => $t +xt]); my $srl_x = $textarea -> Scrollbar(-orient=>'h',-command=>[xview => $t +xt]); $txt -> configure(-yscrollcommand=>['set', $srl_y], -xscrollcommand=>['set',$srl_x]); $lab -> grid(-row=>1,-column=>1); $ent -> grid(-row=>1,-column=>2); $frm_name -> grid(-row=>1,-column=>1,-columnspan=>2); $but -> grid(-row=>4,-column=>1,-columnspan=>2); $txt -> grid(-row=>1,-column=>1); $srl_y -> grid(-row=>1,-column=>2,-sticky=>"ns"); $srl_x -> grid(-row=>2,-column=>1,-sticky=>"ew"); $textarea -> grid(-row=>5,-column=>1,-columnspan=>2); MainLoop; #This function will be executed when the button is pushed sub push_button { my $ip = $ent -> get(); my $ping = `ping $ip`; $txt -> insert('end', "$ping");#Here is not the results of real-time d +isplay }

Here to run the results without scrolling display, how to modify?

Thanks!

Replies are listed 'Best First'.
Re: How the Perl/TK scroll box like MSDOS rolling display data?
by zentara (Cardinal) on Nov 28, 2012 at 10:50 UTC
    Try this alternative:

    #!/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 { #print "Open Filehandle\n" or die "can't fork: $!"; 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
Re: How the Perl/TK scroll box like MSDOS rolling display data?
by choroba (Cardinal) on Nov 28, 2012 at 09:40 UTC
    Maybe Tk::after can help you.
    Update: Example code:
    #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = new MainWindow::; my $frm_name = $mw->Frame(); my $lab = $frm_name->Label(-text => 'IP:'); my $ent = $frm_name->Entry(); my ($txt, $but); $but = $mw->Button(-text => 'Start Ping', -command => sub { push_button($but, $txt, $ +ent) }); my $textarea = $mw->Frame(); $txt = $textarea->Text(-width => 40, -height => 10); my $srl_y = $textarea->Scrollbar(-orient=>'v', -command => [yview = +> $txt]); my $srl_x = $textarea->Scrollbar(-orient=>'h', -command => [xview = +> $txt]); $txt->configure(-yscrollcommand => ['set', $srl_y], -xscrollcommand => ['set', $srl_x]); $lab->grid(-row => 1, -column => 1); $ent->grid(-row => 1, -column => 2); $frm_name->grid(-row => 1, -column => 1, -columnspan => 2); $but->grid(-row => 4, -column => 1, -columnspan => 2); $txt->grid(-row => 1, -column => 1); $srl_y->grid(-row => 1, -column => 2, -sticky => 'ns'); $srl_x->grid(-row => 2, -column => 1, -sticky => 'ew'); $textarea->grid(-row => 5, -column => 1, -columnspan => 2); MainLoop(); sub push_button { my ($but, $txt, $eng) = @_; open my $PING, '-|', 'ping', $eng->get or die; $but->configure(-state => 'disabled'); $txt->repeat(1000, sub {$txt->insert('end', scalar <$PING>)}); }
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Hi,Run your program error is as follows:

      E:\Study area\program_myself>perl t.pl

      Tk::Error: List form of pipe open not implemented at t.pl line 42.

      Tk callback for .button

      Tk::__ANON__ at C:/Perl/site/lib/Tk.pm line 250

      Tk::Button::butUp at C:/Perl/site/lib/Tk/Button.pm line 175

      <ButtonRelease-1>

      (command bound to event)

      Thanks.

        Oh, OK, you are on MSWin. Change line 43 to
        open my $PING, 'ping ' . $eng->get . ' |' or die;
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: How the Perl/TK scroll box like MSDOS rolling display data?
by Anonymous Monk on Nov 28, 2012 at 09:41 UTC