Python 如何在pyautogui中单击图像中心

Python 如何在pyautogui中单击图像中心,python,pyautogui,Python,Pyautogui,我想点击图像的中心,那么我能做什么呢?我厌倦了在pyautogui中点击图像的中心 例如,对于图像,我们需要编写以下内容: pyautogui.locateOnScreen('image.png') 如何定位图像的中心?您可以使用内置方法直接找到图像的中心 返回屏幕上第一个找到的图像实例的中心坐标。如果在屏幕上找不到,则引发ImageNotFoundException。正如codelt所说,屏幕上的LocateCenter(图像)将返回x,y,这是最有效的方法 要获得更大的灵活性,请记住loc

我想点击图像的中心,那么我能做什么呢?我厌倦了在pyautogui中点击图像的中心

例如,对于图像,我们需要编写以下内容:

pyautogui.locateOnScreen('image.png')

如何定位图像的中心?

您可以使用内置方法直接找到图像的中心


返回屏幕上第一个找到的图像实例的中心坐标。如果在屏幕上找不到,则引发
ImageNotFoundException

正如codelt所说,屏幕上的LocateCenter(图像)将返回x,y,这是最有效的方法

要获得更大的灵活性,请记住locateOnScreen()也将采用信心参数。这使您可以灵活地确定在它返回坐标之前它的确定程度。然后,您可以通过center()运行它,它将返回X,y坐标

例如,如果pyautogui很难找到置信度较高的图像,但可以找到置信度较低的图像:

locateCenterOnScreen(image)
#returns None

locateOnScreen(image, confidence=0.7)
#returns box coordinates as it found the image at a lower confidence

pyautogui.center(pyautogui.locateOnScreen(image,confidence=0.7))
#returns center coordinates, exactly the same as locateCenterOnScreen

我能在pyautogui中找到一张看起来像图片的图片吗!你能解释一下你的代码并告诉我它有什么帮助吗?您可能需要签出。是的,当然,
locateCenterOnScreen('neverbtn.png')
此函数返回图像中心的坐标(x,y),例如,如果您有这样的图像,请传递(x,y)以单击pyautogui的()函数
locateCenterOnScreen(image)
#returns None

locateOnScreen(image, confidence=0.7)
#returns box coordinates as it found the image at a lower confidence

pyautogui.center(pyautogui.locateOnScreen(image,confidence=0.7))
#returns center coordinates, exactly the same as locateCenterOnScreen
x, y = pyautogui.locateCenterOnScreen('neverbtn.png')
pyautogui.click(x, y)