0
0

More than 3 years have passed since last update.

PyAutoGUIで、複数の画像を与えて座標を返す。

Last updated at Posted at 2020-12-17
import pyautogui

def locate_first_center(pictures_path: list):
    """
    Args
        pictures_path(list): list of paths
    Returns
        Coordinates if one of the pictures is found.
        None if none of the pictures are found.
    """
    if len(pictures_path) < 1:
        raise IndexError
    for picture in pictures_path:
        center = pyautogui.locateCenterOnScreen(picture)
        if center:
            return center   # Coordinates of the found picture
    return center   # None or coordinates of the morst right picture.


if __name__ == "__main__":
    # a.pngがなければb.pngをクリックする
    pos = locate_first_center(['a.png', 'b.png'])
    click(pos)
0
0
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0