首页 > 解决方案 > 即使不在屏幕上也能找到图像

问题描述

我正在尝试构建一个基本宏来判断我的生命条是否很低,但我的程序中有一个错误,即使 lifebar.png 不在屏幕上,它仍然会打印“我可以看到它”。谁能解释为什么会这样?也有人可以向我展示一个示例,其中 pyautogui 以 x 置信度定位图像然后单击它?谢谢。

lasthit = pyautogui.locateAllOnScreen('lifebar.png', confidence=(1))
def new_method(lasthit):
    while True:
        if lasthit is not None:
            print("I can see it.")
            time.sleep(2)
        else:
            print("image not found")
            time.sleep(0.5)
new_method(lasthit)

标签: python

解决方案


推荐阅读