我正在创建一个脚本来识别一个图像并执行一些操作,基本上当我发现图像是一个操作时,当我找不到时,就执行另一个操作。 但是当找不到映像时,pyautogui本身已经返回错误并关闭函数。返回以下错误:ImageNotFoundExeption('找不到图像….') 我基本上需要它来工作
print('Press Ctrl-C to quit.')
try:
while True:
def locate_img(img):
locate = pyautogui.locateOnScreen(img)
if locate:
X,Y = pyautogui.center(locate)
pyautogui.moveTo(X,Y, 0.2)
else:
X,Y = pyautogui.center(locate)
pyautogui.moveTo(X,Y, 0.2)
locate_img(find)
except KeyboardInterrupt:
print('\nDone.')
如果图像未定位,则会返回locate中的直接错误,甚至不会转到else
也许你会想要在try-except块中抛出错误的实际部分,而不是全部。你知道吗
您可以使用许多,除非egx需要:
例外情况充当通配符
相关问题 更多 >
编程相关推荐