简体   繁体   English

我无法停止python中的循环

[英]I can't stop the loop in python

Here is my problem, I'm a beginner and I try to loop a "find and click" on a specific image ( the "NON" button ), it works but the loop don't stop when all the images are clicked. 这是我的问题,我是一个初学者,我尝试在特定图像上循环“查找并单击”(“ NON”按钮),它可以工作,但是当单击所有图像时循环不会停止。

How can I tell it that when there's no image left to stop the loop and continue with the code? 我怎么能告诉我,当没有图像可以停止循环并继续执行代码时?

here's my code: 这是我的代码:

NON2 = pyautogui.locateCenterOnScreen('NON2.png', grayscale=True, confidence=0.9)

while NON2:
    time.sleep(2)
    click = pyautogui.locateCenterOnScreen('NON2.png', grayscale=True, confidence=0.9)
    pyautogui.click(click)

pyautogui.click(44,965)

and here's the screenshot of the "non" button: 这是“非”按钮的屏幕截图:

NON按钮

DISCALIMER I don't know pyautogui. 免责声明,我不了解pyautogui。

You'll never update the NON2 button in the loop. 您永远不会在循环中更新NON2按钮。 Try this: 尝试这个:

NON2 = pyautogui.locateCenterOnScreen('NON2.png', grayscale=True, confidence=0.9)

while NON2:
    time.sleep(2)
    NON2 = pyautogui.locateCenterOnScreen('NON2.png', grayscale=True, confidence=0.9)
    pyautogui.click(NON2)

pyautogui.click(44,965)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM