检测与其他画布图像重叠的画布图像Python Tkinter

时间:2018-09-11 16:31:29

标签: python tkinter

Python 3.5.2

我正在尝试从canvas.create_image与另一个canvas.create_image重叠时获得输出。当我尝试canvas.find_overlapping时收到错误消息:ValueError: not enough values to unpack (expected 4, got 2)

代码如下:

finish = canvas.create_image(100, 200, image=img2, anchor='nw')
img = canvas.create_image(100, 100, image=img1, anchor='nw')
def checkfinish():
    x1, y1, x2, y2 = canvas.coords(img)
    result = canvas.find_overlapping(x1, y1, x2, y2)
    if finishline in result:
        print('overlaps')
    root.after(250, checkfinish)

注意:canvas,img1等。已经定义,这只是相关代码。

谢谢

1 个答案:

答案 0 :(得分:1)

我的猜测是您需要图像的边界框,而不是坐标。将checkfinish中的第一行更改为:

x1, y1, x2, y2 = canvas.bbox(img)