9.11. 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 14). To do this, use the canvasx and canvasymethods:

$x = $canvas->canvasx(screenx [, gridspacing ]);
$y = $canvas->canvasy(screeny [, gridspacing ]);

Each method takes an optional gridspacing argument; then the canvas coordinate value will be rounded to the nearest value to fit the grid.

Get Learning 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.