Search code examples
pythonpyautogui

How to click on center of image in pyautogui


I want to click on the center of the image so what can I do I'm tired to click on the centre of the image in pyautogui

For Example for an image we need to write this:

pyautogui.locateOnScreen('image.png')

How Can I locate the center of the image?


Solution

  • You can directly find the center of the image using the built in locateCenterOnScreen method.

    locateCenterOnScreen(image, grayscale=False)
    

    Returns (x, y) coordinates of the center of the first found instance of the image on the screen. Raises ImageNotFoundException if not found on the screen.