Before we let the user draw on the canvas, we need to bind the canvas event to mouse movements and mouse click.
Drawing or adding any item on to the Canvas widget first requires that we know the coordinates of the location where the item is to be placed.
Note
The Canvas widget uses two coordinate systems to track positions:
Window coordinate system: Coordinate as expressed in relation to root window
Canvas coordinate system: Coordinate as expressed as position of item within the canvas
You can convert from window coordinates to canvas coordinates using the canvasx
and canvasy
methods as follows:
canx = canvas.canvasx(event.x) cany = canvas.canvasy(event.y)
Drawing any item on the canvas would begin when the user clicks the mouse button. The drawing needs to continue till the mouse is moved with the button pressed and up to the time the mouse button is released.
Thus, we need to track...