f



Perl Tk Error

Hi,

while running my perl tk script I got an error like "Bad Screen Distance", please someone helpme regarding this issue. Thanks in advance. Here is a code for reference.


use Tk;

my $mw    = new MainWindow(-title => 'TEST');
$mw->geometry("500x500");
my $canvas    = $mw1->Canvas(
                        -width  => 350, 
                        -height => 350,
                        -background=>'white')
                     ->pack();


my @arr1 = (10,100,200,150,250);
my $len = @arr1;

$ver = $canvas->createLine(5,5,5,250,
                           -width=>4,
                           -arrow=>'first',
                           -arrowshape=>[5,5,5]);

$hor = $canvas->createLine(3,250,250,250,
                           -width=>4,
                           -arrow=>'last',
                           -arrowshape=>[5,5,5]);

for (my $lp = 1,my $y=20,my $n=1,my $x=0; $lp <= $len ; $lp++,$y+=10,$n++,$x++ ){ 

$id = $canvas->createLine($arr1[$x],$y,$arr1[$x+2],$y,
                           -width=>1,
                           -arrow=>'both',
                           -arrowshape=>[3,3,3]);
$tx = $canvas->createText(int(($arr1[$x]+$arr1[$x+2])/2),$y,-text=>"$n");
                     }

$bt = $mw1->Button(
                  -text=>'Quit',
                  -command=>sub {exit})
               ->pack(
                     -side=>'bottom');
                  
MainLoop;
0
Anoop
7/21/2015 9:51:59 AM
comp.lang.perl.tk 4721 articles. 0 followers. pharrendorf (19) is leader. Post Follow

3 Replies
623 Views

Similar Articles

[PageSpeed] 37

What line number? What is the actual, complete message?

In article <0a2cfd07-a953-4d96-8666-46e122bece75@googlegroups.com>, anoopnag007@gmail.com says...
> 
> Hi,
> 
> while running my perl tk script I got an error like "Bad Screen Distance", please someone helpme regarding this issue. Thanks in advance. Here is a code for reference.
> 
> 
> use Tk;
> 
> my $mw    = new MainWindow(-title => 'TEST');
> $mw->geometry("500x500");
> my $canvas    = $mw1->Canvas(
>                         -width  => 350, 
>                         -height => 350,
>                         -background=>'white')
>                      ->pack();
> 
> 
> my @arr1 = (10,100,200,150,250);
> my $len = @arr1;
> 
> $ver = $canvas->createLine(5,5,5,250,
>                            -width=>4,
>                            -arrow=>'first',
>                            -arrowshape=>[5,5,5]);
> 
> $hor = $canvas->createLine(3,250,250,250,
>                            -width=>4,
>                            -arrow=>'last',
>                            -arrowshape=>[5,5,5]);
> 
> for (my $lp = 1,my $y=20,my $n=1,my $x=0; $lp <= $len ; $lp++,$y+=10,$n++,$x++ ){ 
> 
> $id = $canvas->createLine($arr1[$x],$y,$arr1[$x+2],$y,
>                            -width=>1,
>                            -arrow=>'both',
>                            -arrowshape=>[3,3,3]);
> $tx = $canvas->createText(int(($arr1[$x]+$arr1[$x+2])/2),$y,-text=>"$n");
>                      }
> 
> $bt = $mw1->Button(
>                   -text=>'Quit',
>                   -command=>sub {exit})
>                ->pack(
>                      -side=>'bottom');
>                   
> MainLoop;



-- 
Replace "usenet" with "marc" in the e-mail address.
0
Marc
7/21/2015 3:55:46 PM
On 7/21/2015 02:51, Anoop Nagesh wrote:
> use Tk;
>
> my $mw    = new MainWindow(-title => 'TEST');
> $mw->geometry("500x500");
> my $canvas    = $mw1->Canvas(
>                          -width  => 350,
>                          -height => 350,
>                          -background=>'white')
>                       ->pack();
>
>
> my @arr1 = (10,100,200,150,250);
> my $len = @arr1;
>
> $ver = $canvas->createLine(5,5,5,250,
>                             -width=>4,
>                             -arrow=>'first',
>                             -arrowshape=>[5,5,5]);
>
> $hor = $canvas->createLine(3,250,250,250,
>                             -width=>4,
>                             -arrow=>'last',
>                             -arrowshape=>[5,5,5]);
>
> for (my $lp = 1,my $y=20,my $n=1,my $x=0; $lp <= $len ; $lp++,$y+=10,$n++,$x++ ){
>
> $id = $canvas->createLine($arr1[$x],$y,$arr1[$x+2],$y,
>                             -width=>1,
>                             -arrow=>'both',
>                             -arrowshape=>[3,3,3]);
> $tx = $canvas->createText(int(($arr1[$x]+$arr1[$x+2])/2),$y,-text=>"$n");
>                       }
>
> $bt = $mw1->Button(
>                    -text=>'Quit',
>                    -command=>sub {exit})
>                 ->pack(
>                       -side=>'bottom');
>
> MainLoop;

I played around with this a bit and I think I know what's wrong.

use strict;
use warnings;
use Tk;

my $mw = new MainWindow(-title => 'TEST');
$mw->geometry("500x500");
my $canvas = $mw->Canvas(-width  => 350, -height => 350,
   -background => 'white')->pack();
my @arr1 = (10, 100, 200, 150, 250);
my $len = @arr1;
my $ver = $canvas->createLine(5, 5, 5, 250, -width => 4, -arrow => 'first',
   -arrowshape => [5, 5, 5]);
my $hor = $canvas->createLine(3, 250, 250, 250, -width => 4, -arrow => 'last',
   -arrowshape => [5, 5, 5]);

my $y = 20; my $n = 1; my $x = 0;
for (my $lp = 1; $lp < $len; $lp++) {

# the x+2 below and the $lp <= $len above caused indexing past the end of @arr1
# I changed it to $x+1 and $lp < $len - not sure if that's what's wanted, but no err.

	my $id = $canvas->createLine($arr1[$x], $y, $arr1[$x+1], $y,
	  -width => 1, -arrow => 'both', -arrowshape => [3, 3, 3]);
	my $tx = $canvas->createText(int (($arr1[$x] + $arr1[$x+1]) / 2), $y,
	  -text => $n);
	$y += 10; $n++; $x++;
}
my $bt = $mw->Button(-text => 'Quit', -command => sub { exit; })->pack(
   -side => 'bottom');
MainLoop;

__END__
0
Bill
7/22/2015 1:04:38 AM
On 7/21/2015 18:04, $Bill wrote:
> On 7/21/2015 02:51, Anoop Nagesh wrote:
>> use Tk;
>>
>> my $mw    = new MainWindow(-title => 'TEST');
>> $mw->geometry("500x500");
>> my $canvas    = $mw1->Canvas(
>>                          -width  => 350,
>>                          -height => 350,
>>                          -background=>'white')
>>                       ->pack();
>>
>>
>> my @arr1 = (10,100,200,150,250);
>> my $len = @arr1;
>>
>> $ver = $canvas->createLine(5,5,5,250,
>>                             -width=>4,
>>                             -arrow=>'first',
>>                             -arrowshape=>[5,5,5]);
>>
>> $hor = $canvas->createLine(3,250,250,250,
>>                             -width=>4,
>>                             -arrow=>'last',
>>                             -arrowshape=>[5,5,5]);
>>
>> for (my $lp = 1,my $y=20,my $n=1,my $x=0; $lp <= $len ; $lp++,$y+=10,$n++,$x++ ){
>>
>> $id = $canvas->createLine($arr1[$x],$y,$arr1[$x+2],$y,
>>                             -width=>1,
>>                             -arrow=>'both',
>>                             -arrowshape=>[3,3,3]);
>> $tx = $canvas->createText(int(($arr1[$x]+$arr1[$x+2])/2),$y,-text=>"$n");
>>                       }
>>
>> $bt = $mw1->Button(
>>                    -text=>'Quit',
>>                    -command=>sub {exit})
>>                 ->pack(
>>                       -side=>'bottom');
>>
>> MainLoop;
>
> I played around with this a bit and I think I know what's wrong.
>
> use strict;
> use warnings;
> use Tk;
>
> my $mw = new MainWindow(-title => 'TEST');
> $mw->geometry("500x500");
> my $canvas = $mw->Canvas(-width  => 350, -height => 350,
>    -background => 'white')->pack();
> my @arr1 = (10, 100, 200, 150, 250);
> my $len = @arr1;
> my $ver = $canvas->createLine(5, 5, 5, 250, -width => 4, -arrow => 'first',
>    -arrowshape => [5, 5, 5]);
> my $hor = $canvas->createLine(3, 250, 250, 250, -width => 4, -arrow => 'last',
>    -arrowshape => [5, 5, 5]);
>
> my $y = 20; my $n = 1; my $x = 0;
> for (my $lp = 1; $lp < $len; $lp++) {
>
> # the x+2 below and the $lp <= $len above caused indexing past the end of @arr1
> # I changed it to $x+1 and $lp < $len - not sure if that's what's wanted, but no err.

OK, the $lp <= $len is OK - since you're base 1 indexing, but $x still needs to
stay inside the @arr1 bounds.  $lp isn't really needed if you use $x for indexing
and $n is simply $x+1.  See below:

my $y = 20;
for (my $x = 0; $x < @arr1 - 1; ++$x) {	# switched to $x for index and base 0 indexing
	my $id = $canvas->createLine($arr1[$x], $y, $arr1[$x+1], $y,
	  -width => 1, -arrow => 'both', -arrowshape => [3, 3, 3]);
	my $tx = $canvas->createText(int (($arr1[$x] + $arr1[$x+1]) / 2), $y,
	  -text => $x+1);
	$y += 10;
}

>      my $id = $canvas->createLine($arr1[$x], $y, $arr1[$x+1], $y,
>        -width => 1, -arrow => 'both', -arrowshape => [3, 3, 3]);
>      my $tx = $canvas->createText(int (($arr1[$x] + $arr1[$x+1]) / 2), $y,
>        -text => $n);
>      $y += 10; $n++; $x++;
> }
> my $bt = $mw->Button(-text => 'Quit', -command => sub { exit; })->pack(
>    -side => 'bottom');
> MainLoop;
>
> __END__
0
Bill
7/24/2015 6:52:10 PM
Reply: