【问题标题】:locateCenterOnScreen receives errors once the image is undetected instead of trying it over一旦未检测到图像,locateCenterOnScreen 就会收到错误,而不是重试
【发布时间】:2020-11-18 05:42:33
【问题描述】:
代码在看到图像时工作,但是它放弃(一个错误说“无法解压缩不可迭代的 NoneType 对象”)而不是在它正在查看的图像受到某些情况的影响时重试,例如移动一个阻塞的窗口代码视图。
这是代码
import pyautogui
while True:
x, y = pyautogui.locateCenterOnScreen('icon.png', confidence=0.8)
print(x, y)
【问题讨论】:
标签:
python
image
image-recognition
pyautogui
【解决方案1】:
看起来我自己找到了解决方案,将“x,y”替换为任意字母。
这里是没有收到错误的代码:
点击图片:
import pyautogui
while True:
f = pyautogui.locateCenterOnScreen('icon.png')
pyautogui.click(f)
打印图片的位置:
#! python3
import pyautogui
while True:
f = pyautogui.locateCenterOnScreen('icon.png')
print(f)