首页 > 解决方案 > pyautogui.locateOnScreen() 用于多个图像?

问题描述

你会如何pyautogui.locateOnScreen()处理多个图像一堆图像?

标签: pythonpyautogui

解决方案


试试这个:

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))

这个问题与另一个问题相似我在两个地方都发布了相同的答案。


推荐阅读