python - 即使不在屏幕上也能找到图像
问题描述
我正在尝试构建一个基本宏来判断我的生命条是否很低,但我的程序中有一个错误,即使 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)
解决方案
推荐阅读
- html - 您如何解决 img 和屏幕左侧之间的差距以及导航栏选项不匹配的问题?
- javascript - 即使在半空中,如何让球在点击时再次反弹?
- string - 如何测试一个字母是否在列表中?
- laravel - Laravel Mix:提取供应商有什么好处?
- javascript - 有没有更好的方法将多个道具传递给 n 个孩子
- twitter-bootstrap - 编写自定义类与 .container-fluid 相同
- javascript - 如何在Javascript中删除数组中的重复数组?
- python - 绘图显示 Jupyter 中的错误点
- macos - 替换字符applescript时出错
- quantum-computing - Hadamarding 的目的是什么,然后在传送期间测量消息?