NaN NaN 中的 PyAutoGui

PyAutoGui Nan NaN NaN

pyautogui.displayMousePosition() 显示 848 Y: 853 RGB: (NaN, NaN, NaN)

我不确定为什么它不能拾取 RGB 颜色。谢谢

确保 sys.platform == "darwin" returns 错误。正如您在 PyAutoGui 的 python 文件中所见:

if not onScreen(x - xOffset, y - yOffset) or sys.platform == "darwin":
    # Pixel color can only be found for the primary monitor, and also not on mac due to the screenshot having the mouse cursor in the way.
    pixelColor = ("NaN", "NaN", "NaN")

如果sys.platform returns "darwin",你得到RGB: (NaN, NaN, NaN)结果是正常的。

要解决此问题,您只需执行以下操作:

import sys

sys.platform = '_' # sys.platform is no longer "darwin"
pyautogui.displayMousePosition()