I can't seem to figure out how to retrieve the x,y
position of an oval created on a Tkinter canvas using Python via
c.create_oval(x0, y0, x1, y2)
I understand that Tkinter
creates the oval inside the box specified by x0,y0,x1,y2
and if I can get those coordinates that would also work.
I need the coordinates to move the oval by an offset equal to the mouse coords and the actual oval.
In most cases it will be a 4-tuple (x1 , y1 , x2 , y2 ) describing the bounding box of the object . The rule of thumb is that if it takes two coordinates to define the object (text in your case), then that is the number of coordinates the command will return.
The coordinate space of the canvas has 0, 0 at the top left corner. Larger X coordinates are to the right, and larger Y coordinates are downward. The position and possibly the size of a canvas object is determined by a set of coordinates.
You can use . moveto(item_id, x, y) to move the canvas item to absolute position (x, y) .
A Frame is designed to be a parent container of other widgets. A Canvas is like a canvas that you can draw somethings on it like lines, circles, text, etc. A Canvas can be used as a parent container as well but it is not designed for that at the first place.
Assign the results of c.create_oval
to x
-- that's the "object ID" of the oval. Then,
c.coords(x)
gives you the (x1, y1, x2, y2)
tuple of the oval's coordinates (you call coords
with new coordinates following the x
to move the oval).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With