Hello! Finally had a question I couldn't figure out or find on my own, so I request the wisdom of the keepers of Perl knowledge. I have a program which uses Tk::canvas, and I am trying to gather the coordinates of a mouse click on the canvas. What I would like to know is why the first bit of code works, where as numerous attempts at code similar to the second bit does not.
Works:$canvas{'ref'}->CanvasBind("<1>", [ \&print_xy, Ev('x'), Ev('y') ]); sub print_xy{ my ($canv, $x, $y) = @_; print "(x,y) = ", $canv->canvasx($x), ", ", $canv->canvasy($y), "\n +"; }
Doesn't work:
The second bit of code gives me 'bad screen distance x', which I know from trying is what I get when I dereference $x. I've tried various bits of dereferencing and such playfulness with the $screenX and $x values, and various things to try and get useful data, but it is all for not. I suspect there's something fundamental that is different which I don't know; can anyone shed some light on my conundrum? Thanks!$canvas{'ref'}->CanvasBind("<1>" => sub{ my $screenX = Ev('x'); my $screenY = Ev('y'); my $x = $canvas{'ref'}->canvasx($screenX); my $y = $canvas{'ref'}->canvasy($screenY); print "($x,$y)\n"; });
In reply to Tk::canvas - Cavas coord problem by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |