【问题标题】:Pyautogui change search areaPyautogui 更改搜索区域
【发布时间】:2021-01-23 12:23:57
【问题描述】:

在 pyautogui 中,我正在开发钢琴瓷砖机器人。有没有办法要么只在某个区域寻找一张图片,要么点击该图片的所有实例?

例子:

import pyautogui

time.sleep(5):
pyautogui.click("Tile.png")

【问题讨论】:

    标签: python python-3.x bots pyautogui


    【解决方案1】:

    有点晚了,但是对于那些仍然想知道的人,您可以使用locateCenterOnScreen(picture, confidence, region=(left, top, width, height)) 来查找指定区域的匹配项。 (参数区域是可选的,你也可以使用没有它的功能。)

    center = pyautogui.locateCenterOnScreen("pic_to_find.png", confidence = 0.8)
    pyautogui.click(center.x, center.y)
    

    如果找不到图片,您将获得None 作为回报。所以你可以做类似的事情

    while pyautogui.locateCenterOnScreen("Tile.png", confidence = 0.8) != None:
        click on it
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-17
      • 2016-10-10
      • 1970-01-01
      • 1970-01-01
      • 2011-03-13
      • 2018-08-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多