in reply to Tk::canvas - Cavas coord problem

Try something like this:
use strict; use warnings; use Tk; my $main = new MainWindow; my $c = $main->Canvas( -width => 200, -height => 200, -relief => 'sunken', -borderwidth => 2, )->pack( -expand => 1, -fill => 'both', ); $c->CanvasBind( '<1>' => sub { my ($c) = @_; my $e = $c->XEvent; my $x = $c->canvasx( $e->x ); my $y = $c->canvasy( $e->y ); print "$x,$y\n"; } ); MainLoop;

And it's better not to use Perl's reserved words for variable names or hash keys, in this case 'ref'.

Replies are listed 'Best First'.
Re^2: Tk::canvas - Cavas coord problem
by GenViper (Initiate) on May 12, 2010 at 19:18 UTC
    Thanks! The code does exactly what I'm looking for, guess I was just going about it slightly wrong. And yea, I suppose it's probably best not to use 'ref' to ensure it doesn't cause unexpected weirdness down the road, but it's just so darn convenient! ;)