Skip to content Skip to sidebar Skip to footer

Pyautogui.locateOnScreen() For Multiple Images?

How would you do pyautogui.locateOnScreen() for multiple images a bunch of images?

Solution 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.


Post a Comment for "Pyautogui.locateOnScreen() For Multiple Images?"