2024-05-29 04:30:30 发布
网友
在Pyatogui中,我正在开发一个钢琴瓷砖机器人。有没有办法只在某个区域中查找图像,或者单击该图像的所有实例
例如:
import pyautogui time.sleep(5): pyautogui.click("Tile.png")
虽然有点晚了,但是对于那些仍然感到疑惑的人来说,您可以使用locateCenterOnScreen(picture, confidence, region=(left, top, width, height))在指定区域上查找匹配项。(参数区域是可选的,您也可以在没有参数区域的情况下使用该函数。)
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作为回报。所以你可以做一些像
None
while pyautogui.locateCenterOnScreen("Tile.png", confidence = 0.8) != None: click on it
虽然有点晚了,但是对于那些仍然感到疑惑的人来说,您可以使用
locateCenterOnScreen(picture, confidence, region=(left, top, width, height))
在指定区域上查找匹配项。(参数区域是可选的,您也可以在没有参数区域的情况下使用该函数。)如果找不到图片,您将得到
None
作为回报。所以你可以做一些像相关问题 更多 >
编程相关推荐