Python Forum
PyautoGUI- How to use If - Else with pyautogui.locateCenterOnScreen
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyautoGUI- How to use If - Else with pyautogui.locateCenterOnScreen
#1
Essentially I want my Python script to perform this...

     x = True
     if x  == True:
         print('Congratulations, you won!')
     else:
         print('I'm sorry but you lost.')
with this...

     a, b = pyautogui.locateCenterOnScreen('~/home/file_01.png', region=(1065,250,385,700), confidence=0.9)

In other words, how can I have my script check to see if PyautoGUI has successfully located the center of ~/home/file_01.png?

See, about 95% of the time the following works correctly....

     a, b = pyautogui.locateCenterOnScreen('~/home/file_01.png', region=(1065,250,385,700), confidence=0.9)
But about 5% of the time ~/home/file_01.png does not exist. In those cases my script stops and throws off the following error message...

     TypeError: cannot unpack non-iterable NoneType object
Instead of having my script stops in cases when ~/home/file_01.png does not exist I would prefer that my script skip that instance. In other words, instead of stopping I want my script to ignore cases when ~/home/file_01.png does not exist.
Reply


Messages In This Thread
PyautoGUI- How to use If - Else with pyautogui.locateCenterOnScreen - by Tiel - Oct-05-2021, 12:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pyautogui, İmagesearch, Moving target Beyazx 0 689 Jun-27-2023, 08:47 PM
Last Post: Beyazx
  PyAutogui write Dollar Sign Dutch keyboard not working alato 0 888 Nov-22-2022, 11:25 PM
Last Post: alato
  pyautogui.locateOnScreen producing error dude8074 6 4,241 Apr-17-2022, 05:05 PM
Last Post: bowlofred
  how to take a screnshot by Pyautogui automatically and randomly rachidel07 0 3,708 Feb-03-2021, 01:16 PM
Last Post: rachidel07
Sad problem with Pyautogui rachidel07 1 2,583 Jan-27-2021, 05:43 PM
Last Post: nilamo
  pyautogui with a display emulator? gumby4231 0 2,732 Jul-30-2020, 02:46 PM
Last Post: gumby4231
  pyautogui.screenshot region is not working alexlu 6 6,809 Jun-04-2020, 10:46 AM
Last Post: alexlu
  loop in pyautogui (python automation GUI application) pyprogrammer 0 4,956 Feb-12-2020, 02:52 PM
Last Post: pyprogrammer
  Doesn't work function pyautogui.typewrite() aliyevmiras 1 4,989 Dec-22-2019, 11:35 AM
Last Post: aliyevmiras
  Pyautogui script runs fine if split into two parts together it does not Bmart6969 1 2,633 Oct-07-2019, 10:53 PM
Last Post: Bmart6969

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020