Translating Coordinates
When you set up a callback and use the
Ev('x')
and/or Ev('y')
arguments to find out where the user clicked, you must translate that
information into Canvas coordinates (Ev
is
explained in Chapter 15). To do this, use the
canvasx
and canvasy
methods:
$x = $canvas->canvasx(screenx [, gridspacing ]
); $y = $canvas->canvasy(screeny [, gridspacing ]
);
Each method takes an optional gridspacing argument; the Canvas coordinate value will be rounded to the nearest value to fit the grid.
Get Mastering Perl/Tk now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.