我一直在用多种形式的代码实现pyautogui.pixel,我会在短时间内获得正常的理想输出,在某个时候,函数会停止工作,我会收到错误消息。
简单示例代码:
while True:
print(pyautogui.pixel(1766, 1539))
输出:
(30, 30, 30)
最终错误消息:
Traceback (most recent call last):
File "c:UserszyoliDesktopscrap_botgathering.py", line 14, in <module>
print(pyautogui.pixel(1766, 1539))
File "C:UserszyoliAppDataLocalProgramsPythonPython39libsite-packagespyscreeze__init__.py", line 584, in pixel
return (r, g, b)
File "C:UserszyoliAppDataLocalProgramsPythonPython39libcontextlib.py", line 124, in __exit__
next(self.gen)
File "C:UserszyoliAppDataLocalProgramsPythonPython39libsite-packagespyscreeze__init__.py", line 113, in __win32_openDC
raise WindowsError("windll.user32.ReleaseDC failed : return 0")
OSError: windll.user32.ReleaseDC failed : return 0
我想您在运行代码时正在切换一些窗口/应用程序。也许是因为动画的原因(打开新窗口时(,Pyautogui引发了一个错误。来自屏幕的get_pixel
速度较慢。也许这个帖子可以帮助你:在Windows 7 上用Python快速获取屏幕上某些像素的颜色