error running a perl TK programme

K

king

I have a script as below to be ran in windows.

But whenever I am running this i am getting an error #No -label at C:/
Perl/lib/Tk/Widget.pm line 256#.
Sometimes I am not getting this error also but I am not getting the
output window also. Even if its not showing any error but it also is
not showing the output window.
What can be the problem?
##########################################
#!\c\perl\bin
use strict;
use warnings;
use tk;

my $main=MainWindow->new();
$main->minsize(qw(250 250));
$main->title(" calculator ");
$main->configure (-background=>'cyan');



my $menu_bar=$main->Frame(-relief=>'groove', -borderwidth=>3, -
background=>'purple',)->pack('-side'=>'top', -fill=>'x');

my $file_mb=$menu_bar->Menubutton(-text=>'File', -
background=>'purple', -activebackground=>'cyan', -
foreground=>'white',)->pack(-side=>'left');
$file_mb->command(label=>'Exit', -activebackground =>'magenta',-
command=> sub{$main->destroy});
$file_mb->separator();

my $help_mb=$menu_bar->Menubutton(-text=>'Help', -
background=>'purple', -activebackground=>'cyan', -
foreground=>'white',)->pack(-side=>'right');
$help_mb->command(-Label=>'About', -activebackground=>'magenta',-
command=> \&about_txt);
$help_mb->command(-Label=>'Help', -activebackground=>'magenta',-
command=> \&help_txt);

$help_mb->separator();

my $top=$main->Frame(-background=>'cyan',)->pack(-side=>'top',-
fill=>'X');
my $left1=$top->Frame(-background=>'cyan',)->pack(-
side=>'left',pady=>9,padx=>8);


my $t1=$left1->Label(-text=>'',-background=>'cyan')->pack();
my $t2=$left1->Label(-text=>'BUS',-background=>'cyan')->pack();
my $t3=$left1->Label(-text=>'DEVICE',-background=>'cyan')->pack();
my $t4=$left1->Label(-text=>'FUNCTION',-background=>'cyan')->pack();


my $left2=$top->Frame(-background=>'cyan',)->pack(-side=>'left',-
pady=>2,-padx=>15);
my $pre = $left2->Label (-text=>'Pretax',-background=>'cyan')->pack();
my $pre1=$left2->Label(-background=>'green', -width=>12, -
borderwidth=>2, -relief=>'sunken')->pack();
my $pre2=$left2->Label(-background=>'green', -width=>12, -
borderwidth=>2, -relief=>'sunken')->pack();
my $pre3=$left2->Label(-background=>'green', -width=>12, -
borderwidth=>2, -relief=>'sunken')->pack();


my $left3=$top->Frame(-background=>'cyan',)->pack(-side=>'left',-
pady=>2,-padx=>15);
my $post = $left3->Label (-text=>'posttax',-background=>'cyan')-
my $post1=$left3->Label(-background=>'green', -width=>12, -
borderwidth=>2, -relief=>'sunken')->pack();
my $post2=$left3->Label(-background=>'green', -width=>12, -
borderwidth=>2, -relief=>'sunken')->pack();
my $post3=$left3->Label(-background=>'green', -width=>12, -
borderwidth=>2, -relief=>'sunken')->pack();


my $left4=$top->Frame(-background=>'cyan',)->pack(-side=>'left',-
pady=>2,-padx=>15);
my $tax = $left4->Label (-text=>'taxation',-background=>'cyan')-
my $tax1=$left4->Label(-background=>'green', -width=>12, -
borderwidth=>2, -relief=>'sunken')->pack();
my $tax2=$left4->Label(-background=>'green', -width=>12, -
borderwidth=>2, -relief=>'sunken')->pack();
my $tax3=$left4->Label(-background=>'green', -width=>12, -
borderwidth=>2, -relief=>'sunken')->pack();


MainLoop();

#No -label at C:/Perl/lib/Tk/Widget.pm line 256
####################################################
 
B

Ben Morrow

Quoth king said:
I have a script as below to be ran in windows.

But whenever I am running this i am getting an error #No -label at C:/
Perl/lib/Tk/Widget.pm line 256#.

Something that often helps when you get a message of this sort is to run
your program with

perl -MCarp=verbose

.. This gives you a full stacktrace on (some) errors, so you can see
where in your script the problem is.
Sometimes I am not getting this error also but I am not getting the
output window also. Even if its not showing any error but it also is
not showing the output window.
What can be the problem?
##########################################
#!\c\perl\bin

I'm not sure what you think this line is doing for you, but a #! line
that doesn't end in 'perl' is a bad idea. perl tries to do clever things
with it for you.
use strict;
use warnings;
use tk;

Perl modules are case-sensitive. While this may work on a
case-insensitive filesystem in some cases, in many (such as use Strict)
it will not.

use Tk;
my $main=MainWindow->new();

I would strongly recommend using

my $main = Tk::MainWindow->new();

instead. Tk really didn't ought to be messing about in other toplevel
namespaces.

my $file_mb=$menu_bar->Menubutton(-text=>'File', -
background=>'purple', -activebackground=>'cyan', -
foreground=>'white',)->pack(-side=>'left');
$file_mb->command(label=>'Exit', -activebackground =>'magenta',-
^^^
Here is your problem. You want -label.

$help_mb->command(-Label=>'About', -activebackground=>'magenta',-
^^^
Here, again, you want -label. Hash keys (and thus Tk configuration
options) are case-sensitive as well.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top