我试图用locateOnWindow()定位图像的坐标
position = pt.locateOnWindow(image, 'Discord', grayscale=True, confidence=.9)
我得到这个错误和不和谐窗口图标变成橙色。图片
提高PyGetWindowException(‘来自Windows的错误代码:%s - %s’% (errorCode,_formatMessage(ErrorCode)) pygetwindow.PyGetWindowException:来自Windows的错误代码:0-操作成功完成。
发布于 2022-02-02 18:25:53
从pyautogui
文档中,正如截图功能所说:您可以调用locateOnScreen()
函数来获取屏幕坐标。返回值是一个4整数元组:(左、顶、宽、高).这个元组可以传递给center()
函数,以获得该区域中心的X
和Y
坐标。
因此,我从笔记本电脑中保存了一个不和谐的图标图像,并找到了正确的坐标,如下所示:
图片:
import pyautogui
image = 'discord.png'
locate = pyautogui.locateOnScreen(image, grayscale=True, confidence=0.8)
position = pyautogui.center(pyautogui.locateOnScreen(image, grayscale=True, confidence=0.8))
如果你print(locate)
Box(left=91, top=288, width=23, height=26)
如果你print(position)
Point(x=102, y=301)
https://stackoverflow.com/questions/70744157
复制相似问题