Working on the answer of my previous question, I wonder how to get the coordinates of the 4 pixels representing the corners of the rectangle as well as its 2 dimensions ?
Advertisement
Answer
You can use canvas.bbox(item)
to get the coordinates of the bounding box of an item on the canvas. Because your item is a rectangle, the bounding box exactly represents the rectangle.
In your case it would be:
JavaScript
x
2
1
self.canvas.bbox(self.rect)
2
This returns a tuple containing (x0, y0, x1, y1)
in which point 0 is the upper left corner and point 1 is the lower right corner.
You can easily convert these to the four corners and sizes:
JavaScript
1
8
1
Upper left = x0, y0
2
Upper right = x1, y0
3
Lower left = x0, y1
4
Lower right = x1, y1
5
6
width = x1-x0
7
height = y1-y0
8