By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,773 Members | 1,724 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,773 IT Pros & Developers. It's quick & easy.

perl tk/command bound to an event

P: 17
when i run my code it's occurred an error

my code...
Expand|Select|Wrap|Line Numbers
  1. sub starting {
  2.  
  3. $out1=`perl macswitch.pl`;
  4.  
  5. foreach ($out1){
  6. chomp;
  7. $tx->insert('end', "$_\n" );
  8. }
  9.  
  10. open (FILE, ">mac.txt")|| die "$!";
  11. print FILE "$out1";
  12. close FILE;
  13.  
  14. open (A, "<mac.txt") || die "$!";
  15. open (B, "<macs.txt") || die  "$!";
  16. local $/;
  17. my @res =();
  18. my @res1 =();
  19. my @res2 =();
  20.  
  21. my @a = split /\n/, <A>;
  22. my @b = split /\n/, <B>;
  23.  
  24. my %a = map { $_ => 1 } @a; # Make hash of B
  25. @res1 = grep { !defined $a{$_} } @b; # Everything in B not in A
  26. $tx2->insert('end', @res1 );
  27.  
  28.  
  29. my %b = map { $_ => 1 } @b; # Make hash of B
  30. @res2 = grep { !defined $b{$_} } @a; # Everything in A not in B
  31. $tx3->insert('end', @res2 );
  32.  
  33. close A;
  34. close B;
  35. }
  36.  
  37. Error is.......
  38.  
  39. Tk::Error: wrong # args: should be ".frame1.text1 insert index chars ?tagList chars tagList ...?" at C:/Perl/lib/Tk.pm line 252, <C> chunk 1.
  40.  Tk callback for .frame1.text1
  41.  Tk callback for .frame.button2
  42.  Tk::__ANON__ at C:/Perl/lib/Tk.pm line 252
  43.  Tk::Button::butUp at C:/Perl/lib/Tk/Button.pm line 111
  44.  <ButtonRelease-1>
  45.  (command bound to event)
  46.  
pls any help..........
Oct 16 '08 #1
Share this Question
Share on Google+
2 Replies


P: 34
I think ,the error lies in your perl-Tk coding while specifying arguements ,

Will you again post your tk code, so that i can able to fix the error..?
Oct 18 '08 #2

P: 17
I think ,the error lies in your perl-Tk coding while specifying arguements ,

Will you again post your tk code, so that i can able to fix the error..?

my tk code.........

#!/usr/bin/perl -w


eval '(exit $?0)' && eval 'exec /usr/local/bin/perl $0 ${1+"$@"}'
&& eval 'exec /usr/local/bin/perl $0 $argv:q'
if 0;

use Tk;
use Tk ':variables';
use strict;
use warnings;
use Tk::Adjuster;
use File::Compare;
use Tk::Frame;
use Tk::TextUndo;
use Tk::Text;
use Tk::Scrollbar;
use Tk::Menu;
use Tk::Menubutton;
use Tk::DialogBox;
use Tk::Label;

use Net::SNMP qw(snmp_dispatcher oid_lex_sort);
use Tk::ItemStyle;
use List::Compare;

################################################## ######
# MAIN WINDOW
################################################## ######

my $mw = MainWindow->new;
$mw->geometry("600x500");
$mw->title("Network Device Monitoring tool");


################################################## #######
# WIDGETS
################################################## #######

#top level frame.....

my $frmTop = $mw->Frame(-bd => 3, -relief => 'ridge')
->pack(-side => 'top', -fill => 'x', -pady => 1);


$frmTop->Button(-text => "get data", -command =>\&pra,-background => '#BC8F8F')->pack(-ipadx => 10,-ipady => 4,-padx => 15,-pady => 15,-side =>"left",-expand
=>"no",-anchor =>"nw");

$frmTop->Button(-text => "new data", -command =>\&pra3,-background => '#BC8F8F')->pack(-ipadx => 10,-ipady => 4,-padx => 150 ,-pady => 15,-side =>"left",-expand
=>"no",-anchor =>"center");

$frmTop->Button(-text => "check", -command =>\&comparing,-background => '#BC8F8F')->pack(-ipadx => 10,-ipady => 4,-padx => 15,-pady => 15,-side =>"right",-expand
=>"no",-anchor =>"e");

#middle level frame......

my $frmMiddle = $mw->Frame(-bd => 3, -relief => 'ridge')
->pack(-side => 'top', -fill => 'x');

my $frmMiddle1 = $frmMiddle->Frame(-bd => 2)->pack(
-side => 'top', -fill => 'x');

$frmMiddle1->Label(-text=>"currently connected ")->pack(-padx => 15,-pady => 1,-side => 'left',-expand =>"no");
$frmMiddle1->Label(-text=>"newly connected")->pack(-padx => 78,-pady => 1,-side => 'left',-expand =>"no");
$frmMiddle1->Label(-text=>"currently not connected")->pack(-padx => 45,-pady => 1,-side => 'right',-expand =>"no");


my $scrollbar1 =$frmMiddle ->Scrollbar( );
my $scrollbar2 =$frmMiddle ->Scrollbar( );
my $scrollbar3 =$frmMiddle ->Scrollbar( );



my $tx = $frmMiddle->Text(-yscrollcommand => ['set' => $scrollbar1],-width =>18,-height =>20,-background =>"white")->pack(-padx => 15,-pady => 10,-side => 'left',-fill =>'both',-expand =>1);
$scrollbar1->configure(-command => ['yview' => $tx]);
$scrollbar1->pack(-side => 'left', -fill => 'y');

my $tx1 = $frmMiddle->Text(-yscrollcommand => ['set' => $scrollbar2],-width =>18,-height =>20,-background =>"white")->pack(-padx => 15,-pady => 10,-side => 'left',-fill =>'both',-expand =>1);
$scrollbar2->configure(-command => ['yview' => $tx1]);
$scrollbar2->pack(-side => 'left', -fill => 'y');

my $tx3 = $frmMiddle->Text(-yscrollcommand => ['set' => $scrollbar3],-width =>18,-height =>20,-background =>"white")->pack(-padx => 15,-pady => 10,-side => 'left',-fill =>'both',-expand =>1);
$scrollbar3->configure(-command => ['yview' => $tx3]);
$scrollbar3->pack(-side => 'left', -fill => 'y');

#bottom level frame....

my $frmBottom = $mw->Frame(-bd => 3, -relief => 'ridge')
->pack(-side => 'top', -fill => 'both');

$frmBottom->Button(-text => "Update", -command =>\&updating,-background => '#BC8F8F')->pack(-ipadx => 10,-ipady => 4,-padx => 15,-pady => 15,-side =>"left",-expand
=>"no",-anchor =>"w");

$frmBottom->Button(-text => "Close", -command =>sub{exit},-background => '#BC8F8F')->pack(-ipadx => 10,-ipady => 4,-padx => 15,-pady => 15,-side =>"right",-expand
=>"no",-anchor =>"e");

thanks for your time,cheers
Oct 21 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.