我试图使用pyautogui "PixelMatchesColor“函数检查屏幕上的像素,但它总是运行代码,即使像素颜色不正确。
这是我的密码:
def myFunction():
im = pyautogui.screenshot()
color = im.getpixel((1992, 1435))
print(color)
try:
pyautogui.pixelMatchesColor(1992, 1435, (85, 214, 142))
print("Color found")
except:
print("Color not found")
输出:
(16, 52, 154)
Color found
你知道我在哪里犯错误吗?
发布于 2022-06-17 09:51:59
如https://pyautogui.readthedocs.io/en/latest/screenshot.html#pixel-matching中所示,pixelMatchesColor
返回布尔值True
或False
以指示颜色是否匹配。
若要在布尔值上分支,请使用if
语句。try
语句用于捕获异常,这在这里是不相关的。
if pyautogui.pixelMatchesColor(1992, 1435, (85, 214, 142)):
print("Color found")
else:
print("Color not found")
https://stackoverflow.com/questions/72657408
复制相似问题