0

In using pyautogui to check if an image is not part of the screen, I tried below:

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

It doesn't seem work well.

What's the proper way to do so? Thank you.

Mark K
  • 8,767
  • 14
  • 58
  • 118
  • Does it throw any error?? – Anwarvic Jun 20 '20 at 16:26
  • 1
    From the [documentation](https://pyautogui.readthedocs.io/en/latest/screenshot.html#the-locate-functions): "`locateOnScreen(image, grayscale=False)` Returns (left, top, width, height) coordinate of first found instance of the `image` on the screen. Raises `ImageNotFoundException` if not found on the screen." However, from your code, it seems like you are expecting it to return a `bool`. – Miguel Alorda Jun 20 '20 at 17:22
  • @Anwarvic, no it doesn't. – Mark K Jun 21 '20 at 08:10
  • @m-alorda, thank you for looking into the documentation. – Mark K Jun 21 '20 at 08:11

1 Answers1

0

Putting it a for loop to continuosly check the presence of the image, once it disappeared, quit the loop.

for _ in range(100):
    time.sleep(1)
    a = pyautogui.locateOnScreen('image.png')
    if a == None:
        print('No this image.')
        break
Tonechas
  • 13,398
  • 16
  • 46
  • 80
Mark K
  • 8,767
  • 14
  • 58
  • 118