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
#4
Here is an additional naive solution without using Exceptions:
import pyautogui
 
coords = pyautogui.locateCenterOnScreen("your_image.png")

# coords is None -> no result
if coords is None:
    print("Could not locate the image")
else:
    x, y = coords  # tuple unpacking
    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!
Reply


Messages In This Thread
RE: PyautoGUI- How to use If - Else with pyautogui.locateCenterOnScreen - by DeaD_EyE - Jun-27-2022, 02:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pyautogui, İmagesearch, Moving target Beyazx 0 684 Jun-27-2023, 08:47 PM
Last Post: Beyazx
  PyAutogui write Dollar Sign Dutch keyboard not working alato 0 879 Nov-22-2022, 11:25 PM
Last Post: alato
  pyautogui.locateOnScreen producing error dude8074 6 4,226 Apr-17-2022, 05:05 PM
Last Post: bowlofred
  how to take a screnshot by Pyautogui automatically and randomly rachidel07 0 3,701 Feb-03-2021, 01:16 PM
Last Post: rachidel07
Sad problem with Pyautogui rachidel07 1 2,582 Jan-27-2021, 05:43 PM
Last Post: nilamo
  pyautogui with a display emulator? gumby4231 0 2,727 Jul-30-2020, 02:46 PM
Last Post: gumby4231
  pyautogui.screenshot region is not working alexlu 6 6,798 Jun-04-2020, 10:46 AM
Last Post: alexlu
  loop in pyautogui (python automation GUI application) pyprogrammer 0 4,954 Feb-12-2020, 02:52 PM
Last Post: pyprogrammer
  Doesn't work function pyautogui.typewrite() aliyevmiras 1 4,975 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,629 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