Question
Why does pyautogui throw an ImageNotFoundException instead of returning None?
I am trying to make image recognition program using pyautogui. I want the program to print "I can see it!"
when it can see a particular image and "Nope nothing there"
when it can't.
I'm testing for this by using pyautogui.locateOnScreen
. If the call returns anything but None
, I print the first message. Otherwise, I print the second.
However, my code is giving me an ImageNotFoundException instead of printing in the second case. Why is this happening?
import pyautogui
while True:
if pyautogui.locateOnScreen('Dassault Falcon 7X.png', confidence=0.8, minSearchTime=5) is not None:
print("I can see it!")
time.sleep(0.5)
else:
print("Nope nothing there")