开发者

How to get the coordinates of an object in a tkinter canvas?

开发者 https://www.devze.com 2022-12-27 19:30 出处:网络
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

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 ova开发者_运维百科l.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消