如果我想查找图像,即使它不是在那个时刻,但在找到它时,我可以使用什么代码?我的代码是:
import pyautogui as auto
import time
import pyautogui
def Saludar (seconds,schedule) :
while (1>0) and (schedule == True) :
time.sleep(seconds)
x, y = auto.locateCenterOnScreen('linea.png', grayscale=True)
auto.moveTo(x,y)
pyautogui.click()
print("YA")
if __name__== "__main__":
Saludar(2,True)
错误:
Traceback (most recent call last):
File "C:/Users/mario/Desktop/buscar aun si no está.py", line 19, in <module>
Saludar(2,True)
File "C:/Users/mario/Desktop/buscar aun si no está.py", line 11, in Saludar
x, y = auto.locateCenterOnScreen('linea.png', grayscale=True)
TypeError: 'NoneType' object is not iterable
当找不到映像时,它将引发
TypeError
异常。您可以使用try/except简单地处理这个问题:相关问题 更多 >
编程相关推荐