How would you do pyautogui.locateOnScreen()
for multiple images a bunch of images?
Asked
Active
Viewed 3,742 times
1

Pymain3664
- 53
- 1
- 8
2 Answers
1
Try this out:
import os
import pyautogui as py
image_list = []
# Get list of all files in current directory
directory = os.listdir()
# Find files that end with .png or .jpg and add to image_list
for file in directory:
if file.endswith('.png') or file.endswith('.jpg'):
image_list.append(file)
# Loop through list to find all the images
for image in image_list:
print(image)
print(py.locateOnScreen(image))
This question is similar to another one, I posted the same answer in both places.

Andrew Stone
- 1,000
- 1
- 7
- 17
0
def get_coordinates(images):
# Capture your screen only once.
haystack = pyautogui.screenshot()
# Loop through multiple images
for needle in images:
# Get coordinates of image within screen capture
return pyautogui.locate(needle, haystack)
print("Images not found!")
Use the screenshot func to capture your screen and then loop through the different images to find a match.
To optimize see optimize

Afro_Jello
- 11
- 3