-1

i want to locateonscreen an image with specific region, but it shows ValueError('needle dimension(s) exceed the haystack image or region dimensions')

There is my code:

while True:
try:
    ikankanan = pyautogui.locateOnScreen('ikankanan.png', region = (389,169,583,45), grayscale = True, confidence = 0.6)
    tanda = pyautogui.locateOnScreen('tandafull.png',region = (389,169,583,45), grayscale = True, confidence = 0.6)
except TypeError:
    pass
except AttributeError:
    pass

2 Answers 2

3

You need to make sure that the image you're trying to find on the screen isn't larger than your display resolution, as an image can't be found in a different image smaller than it.

3
  • i did, look my post i edited it, there is my code
    – Dwika
    Commented Mar 25, 2021 at 4:44
  • What are the sizes of the images you're trying to locate? They probably have to be smaller than the region you specified. Commented Mar 25, 2021 at 5:30
  • the images is within region
    – Dwika
    Commented Mar 25, 2021 at 5:44
3
locateOnScreen('image.file',region=(startXValue,startYValue,width,height),...)

If the dimensions of the image you are looking for exceeds the width and height of the area you are looking in, the method throws an error.

Make sure that the area is large enough to have your image fit inside.

To get the image dimensions on Windows: 'right-click' on the image in your folder, click 'properties' proceed to the tab 'details' there you can see what the minimum 'width' and 'height' should be.

Not the answer you're looking for? Browse other questions tagged or ask your own question.