如何获取 tkinter 画布中对象的坐标? [英] How to get the coordinates of an object in a tkinter canvas?
问题描述
我似乎无法弄清楚如何使用 Python 通过
检索在 Tkinter 画布上创建的椭圆的x,y
位置c.create_oval(x0, y0, x1, y2)
我知道 Tkinter
在 x0,y0,x1,y2
指定的框内创建椭圆,如果我能得到也可以使用的坐标.>
我需要坐标将椭圆移动一个等于鼠标坐标和实际椭圆的偏移量.
将 c.create_oval
的结果赋值给 x
-- 即椭圆形.那么,
c.coords(x)
为您提供椭圆坐标的 (x1, y1, x2, y2)
元组(您将 coords
与 x
后面的新坐标称为> 移动椭圆).
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.
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).
这篇关于如何获取 tkinter 画布中对象的坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!