【问题标题】:How to get the coordinates of an object in a tkinter canvas?如何在 tkinter 画布中获取对象的坐标?
【发布时间】:2010-04-20 23:33:49
【问题描述】:

我似乎不知道如何通过 Python 检索在 Tkinter 画布上创建的椭圆的 x,y 位置

c.create_oval(x0, y0, x1, y2)

我知道Tkinterx0,y0,x1,y2 指定的框内创建了椭圆形,如果我能得到这些坐标也可以。

我需要坐标来将椭圆移动一个等于鼠标坐标和实际椭圆的偏移量。

【问题讨论】:

    标签: python tkinter


    【解决方案1】:

    c.create_oval 的结果分配给x——这就是椭圆的“对象ID”。那么,

    c.coords(x)
    

    为您提供椭圆坐标的 (x1, y1, x2, y2) 元组(您调用 coords 并在 x 之后使用新坐标来移动椭圆)。

    【讨论】:

      猜你喜欢
      • 2012-07-03
      • 1970-01-01
      • 2021-04-24
      • 1970-01-01
      • 1970-01-01
      • 2017-05-28
      • 2022-08-18
      • 1970-01-01
      • 2015-08-01
      相关资源
      最近更新 更多