使用pyautogui等待图像消失

问题描述 投票:0回答:1

在使用 pyautogui 检查图像是否不是屏幕的一部分时,我尝试了以下操作:

a = True
while a is True:
    a = pyautogui.locateOnScreen('image.png')
print ("No this image.')

好像不太好用。

正确的做法是什么?

python pyautogui
1个回答
0
投票

将其置于

for
循环中,不断检查图像是否存在,一旦消失,退出循环。

for _ in range(100):
    time.sleep(1)
    a = pyautogui.locateOnScreen('image.png')
    if a == None:
        print('No this image.')
        break
© www.soinside.com 2019 - 2024. All rights reserved.