如何获取 tkinter 画布中对象的坐标? [英] How to get the coordinates of an object in a tkinter canvas?

查看:76
本文介绍了如何获取 tkinter 画布中对象的坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法弄清楚如何使用 Python 通过

检索在 Tkinter 画布上创建的椭圆的 x,y 位置

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

我知道 Tkinterx0,y0,x1,y2 指定的框内创建椭圆,如果我能得到也可以使用的坐标.>

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

解决方案

c.create_oval 的结果赋值给 x -- 即椭圆形.那么,

c.coords(x)

为您提供椭圆坐标的 (x1, y1, x2, y2) 元组(您将 coordsx 后面的新坐标称为> 移动椭圆).

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆