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)
More than 3 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme