所以我试图这样做,以便它会打印“hello”,直到找到“注销”图像。但除非图像立即出现在屏幕上,否则就会出错。我也尝试过迭代,但这种方法不起作用,因为基本上我希望不断检查该图像是否每秒出现一次。我是超级新手,不擅长这个,所以我确信它很简单,但我似乎找不到它。
import pyautogui as pt
import time as t
import random as rand
import cv2
def check_logout():
logout_image = pt.locateCenterOnScreen('logout.PNG', confidence=.9)
if logout_image is not None:
print("Logout image found. Exiting...")
exit()
else:
print("Hello")
t.sleep(1)
while True:
check_logout()
我希望它不断检查,一旦看到图像就退出脚本。
Pyscreese 文档说明如下:
"""ImageNotFoundException is an exception class raised when the
locate functions fail to locate an image. You must set
pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION to True to enable this feature.
Otherwise, the locate functions will return None."""
尝试将
pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION
设置为 False
以获得预期的功能。
import pyscreeze
pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = False