试图检查像素的颜色:
while True:
x, y = 1742, 979
r,g,b = pyautogui.pixel(x, y)
if b == 106:
#some more code
完整的回溯:
Traceback (most recent call last):
File "C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\pyscreeze\__init__.py", line 119, in __win32_openDC
yield hDC
File "C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\pyscreeze\__init__.py", line 610, in pixel
raise WindowsError("windll.gdi32.GetPixel failed : return {}".format(color))
OSError: windll.gdi32.GetPixel failed : return -1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\OneDrive\Combined_180222_desktop_version .py", line 500, in <module>
detection()
File "c:\Users\OneDrive\Combined_180222_desktop_version .py", line 468, in detection
r,g,b = py.pixel(x, y)
File "C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\pyscreeze\__init__.py", line 614, in pixel
return (r, g, b)
File "C:\Users\AppData\Local\Programs\Python\Python39\lib\contextlib.py", line 135, in __exit__
self.gen.throw(type, value, traceback)
File "C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\pyscreeze\__init__.py", line 123, in __win32_openDC
raise WindowsError("windll.user32.ReleaseDC failed : return 0")
OSError: windll.user32.ReleaseDC failed : return 0
公认的答案here说:“这是PyScreeze 0.1.28中已经解决的问题,所以您只需要通过运行pip install -U pyscreeze
来更新它。”
我上的是PyScreeze 0.1.28,所以不是这样的。公认的答案here谈到手动释放所有DC,但当我直接使用.pixel
函数而不是win32时,我不知道如何做到这一点。
发布于 2022-04-02 13:10:38
解决方法,直到管理包的人回复。不修复错误,只需使用try
和except
处理它。
while True:
try:
x, y = 1742, 979
r,g,b = pyautogui.pixel(x, y)
if b == 106:
#some more code
except:
x, y = 1742, 979
r,g,b = pyautogui.pixel(x, y)
if b == 106:
#some more code
https://stackoverflow.com/questions/71716340
复制相似问题