http://www.perlmonks.org?node_id=1132346

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

HI Perl Monks, Perl version : 5.16.3 Os: Windows 7 64 bit Tk :804.030 installed. For my testing i ve created a piece of code which actually logs in to my Wireless router , configures some value and comes out. For this i created a GUI inteface using Tk having few options which include a "Run" button and a text box ( to print the run time result). When user click on run button, our script starts configuring the wireless router as expected but its not sending the results to the text box of the GUI for successful completion of each test. i could see all the result at once after the entire test is completed. In the below coded this guy is not working as expected for me: $txt -> insert('end',"Executing Security Testcases...\n"); as its getting printed after the entire test is finished. Wondering if the property for button does not alllow realtime displaying in text box. Please help me to resolve this. NOte: i'm a beginner level perl user and google was helping me in writing the below code.

use Tk; use Net::FTP; use Tk::BrowseEntry; #use strict; #use warnings; #local $| = 1; use Tk::Button; use Net::Telnet (); #use File::Copy; $window = MainWindow->new; $window->title("Test WAR"); $window->configure(-background=>'gray79'); $window->geometry( "300x700" ); #$window->Label(-text => " Free Space:",-backg +round => 'gray79')->place(-x=>35,-y=>43); $window->Label(-text => " IP :",-background => + 'gray79')->place(-x=>35,-y=>20); $IP = $window->Entry(-width=>20, -background +=> 'light blue')->place(-x => 120,-y =>20); my $chk1 = $window ->Checkbutton(-activebac +kground => "gray79",-background => 'gray79',-text=>"Security Test",-v +ariable=>\$chkautoTRN)->place(-x =>100,-y =>60); my $chk1 = $window ->Checkbutton(-activebackgr +ound => "gray79",-background => 'gray79',-text=>"Connectivity",-varia +ble=>\$connectivity)->place(-x =>100,-y =>80); #my $chk1 = $window ->Checkbutton(-activebackg +round => "gray79",-background => 'gray79',-text=>"Good Write",-variab +le=>\$chkautoGW)->place(-x =>100,-y =>100); #my $chk1 = $window ->Checkbutton(-activebackg +round => "gray79",-background => 'gray79',-text=>"Flash ROM",-variabl +e=>\$chkautoFR)->place(-x =>100,-y =>120); #my $chk1 = $window ->Checkbutton(-activebackg +round => "gray79",-background => 'gray79',-text=>"Ethernet",-variable +=>\$chkautoE)->place(-x =>100,-y =>140); #my $chk1 = $window ->Checkbutton(-activebackg +round => "gray79",-background => 'gray79',-text=>"Audio",-variable=>\ +$chkautoA)->place(-x =>100,-y =>160); #my $chk1 = $window ->Checkbutton(-activebackg +round => "gray79",-background => 'gray79',-text=>"Micro SD",-variable +=>\$chkautoMSD)->place(-x =>100,-y =>180); #my $chk1 = $window ->Checkbutton(-activebackg +round => "gray79",-background => 'gray79',-text=>"Display",-variable= +>\$chkautoD)->place(-x =>100,-y =>200); #my $chk1 = $window ->Checkbutton(-activebackg +round => "gray79",-background => 'gray79',-text=>"Auto Cab",-variable +=>\$chkautoAC)->place(-x =>100,-y =>220); $window ->Button(-text => "Run", -command =>\& +push_button, -width=>10,-relief => 'groove',-activebackground=>blue,- +relief =>'raised')->place(-x => 50,-y =>600); $window ->Button(-text => "End", -command =>\& +close, -width=>10,-relief => 'groove',-activebackground=>red,-relief +=>'raised')->place(-x =>125,-y =>600);#-relief => 'groove','flat'|'gr +oove'|'raised'|'ridge'|'sunken'|'solid' #$window->Label(-text => "Results",-width=>10, +-background => 'gray79')->place(-x=>35,-y=>250); $txt = $window -> Text(-width=>30, -height=>20 +)->place(-x =>40,-y =>280); $count=1; MainLoop; sub push_button { $host = $IP -> get(); $port = "23"; $uid = "admin"; $pwd = "password123"; open $inputLog, ">in1.log"; $box = new Net::Telnet(); $box->open( Host => $host, Port => $port, ); $iLog = $box->input_log($inputLog); $flag = $box->login( Name => $uid, Password => $pwd, ); if ($chkautoTRN==1) { #sleep 4; $txt -> insert('end',"Executing Security Testcases...\n"); open(MYFILE,'security_profiles.txt'); while (<MYFILE>) { chomp; $x=$_; $box->print($x); $box->waitfor(Match=>'/# $/i',Timeout=>25); #Match=>'/# $/i', #sleep 12; } #$box->close; #system ("cat in.log"); close MYFILE; } if($connectivity==1) { while($count<=100) { system('netsh wlan disconnect'); sleep 2; system('netsh wlan connect name=720wlan0vap7'); #print "wifi connected\n"; sleep 15; $box->cmd('get association station'); $result=$box->lastline; system('netsh wlan disconnect'); #print "wifi disconnected\n"; sleep 15; $txt -> insert('end',"The client $result got connected $count time +\n"); $count++; } } $box->cmd('get association station'); $result=$box->lastline; $txt -> insert('end',"$result\n"); $box->close; } sub close { exit(); }

Replies are listed 'Best First'.
Re: Related with Perl Tk (readline blocking use fileevent)
by Anonymous Monk on Jun 28, 2015 at 09:15 UTC
Re: Related with Perl Tk
by 1nickt (Canon) on Jun 28, 2015 at 12:47 UTC

    Hi, please read the documentation on using this site, especially on how to ask a question ... your question is unreadable as you have posted it. You need paragraph breaks and to enclose your code between code tags.

    Thanks!

Re: Related with Perl Tk
by Lotus1 (Vicar) on Jun 28, 2015 at 14:37 UTC

    Welcome to Perlmonks. Please have a look at the guide to posting effectively for an overview of the markup needed to format your question. Your closing code tag has a backslash instead of a forward slash so it didn't render the code section correctly. Also, the non code section of your question can be formatted with <p> .... </p> tags to separate it into paragraphs.

Re: Related with Perl Tk
by Anonymous Monk on Jun 30, 2015 at 05:01 UTC

    Hi,

    I think you probably want something like $Window->Update(); somewhere in the loop that feeds the text box.

    Sorry to be so vague, your code is a little awkward to read.

    J.C.