Hints

Screen Coordinates vs. Canvas Coordinates

The canvasx and canvasy operations map from a screen coordinate to a canvas coordinate. If the scroll region is larger than the display area, then you need to use these operations to map from the X and Y in an event (i.e., %x and %y) and the canvas coordinates. The typical use is:

set id [$c find closest [$c canvasx %x] [$c canvasy %y]]

Large Coordinate Spaces

Coordinates for canvas items are stored internally as floating point numbers, so the values returned by the coords operation will be floating point numbers. If you have a very large canvas, you may need to adjust the precision with which you ...

Get Practical Programming in Tcl & Tk, Third Edition 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.