在 Python 上搜索两张照片中的一张

问题描述 投票:0回答:1

我有两张照片,我希望 pyautogui 库找到两张照片中的一张,而不是一张一张的,我该怎么做?

我试图让程序点击按钮,但它变成了 发现它依次找到它们,我预计如果没有找到第一个,它会单击第二个

python pyautogui
1个回答
0
投票

试试这个,它对我有用

import pyautogui

# Assuming 'photo1.png' and 'photo2.png' are the filenames of your two photos

try:
    # Try finding and clicking the first photo
    first_photo_location = pyautogui.locateOnScreen('photo1.png')
    pyautogui.click(first_photo_location)
except TypeError:
    # second photo
    second_photo_location = pyautogui.locateOnScreen('photo2.png')
    pyautogui.click(second_photo_location)
© www.soinside.com 2019 - 2024. All rights reserved.