[英]Detect Canvas Image Overlapping Other Canvas Image Python Tkinter
[英]How to find the overlapping of an image on TkInter Canvas (Python)?
在Tkinter中,当我在画布上创建图像并找到其坐标时,它仅返回两个坐标,因此find_overlapping方法不起作用(自然)。 还有其他选择吗?
您应该能够通过调用bbox = canvas.bbox(imageID)
来获取图像的边界框(bbox bbox = canvas.bbox(imageID)
。 然后,您可以使用canvas.find_overlapping(*bbox)
。
它返回的坐标应该是图像左上角的坐标。 因此,如果您获得的坐标是(x, y)
,并且您的图像对象(假设它是一个PhotoImage)是img
,那么您可以执行以下操作:
w, h = img.width(), img.height()
find_overlapping(x, y, x + w, y + h)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.