#๐Ÿ”’ Is it possible to put a 'try: except:' in a Variable?

7 messages ยท Page 1 of 1 (latest)

violet rose
#

I am using pyautogui to detect a Button that shows up on Screen.
start_button = pyautogui.locateOnScreen('startButton.png, confidence=0.8)

it raises an exception if it's not found immediately, so if I want it to constantly check, I need to do this:

  if pyautogui.locateOnScreen('startButton.png', confidence=0.8) != None:
   print('HELLO WORLD')
 except pyautogui.ImageNotFoundException:
  pass```

How can I make it so the Variable example doesn't stop the code when the exception happens?
In context, I want to be able to do this:
``` if start_button != None:
   print('HELLO WORLD')```
deep adderBOT
#

@violet rose

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

foggy halo
#

wrap the thing around a function and return depending on what you ge

midnight estuary
#

i'm not sure i understand the question

#

do you mean you want to assign pyautogui.ImageNotFoundException to a variable so you can inspect it

deep adderBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.