Oct-05-2021, 01:16 PM
The cause is that
You already got the right Exception, which you can catch.
pyautogui.locateCenterOnScreen
return a Point
object or None
if the image was not found on screen.You already got the right Exception, which you can catch.
import pyautogui try: x, y = pyautogui.locateCenterOnScreen("your_image.png") except TypeError: print("Could not locate the image") # this is only executed, if a TypeError was caught # for example you can exit here with sys.exit(1) # or with raise SystemExit("Sorry, image not found") else: # this block is executed, if no exception happened print(f"All fine, got the coordinates: {x} | {y}")
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!