1

I have been implementing pyautogui.pixel in many forms of code, I will get a normal desirable output for a random short while, and at some point, the function will stop working, and I will get error messages.

Simple example code:

while True:
    print(pyautogui.pixel(1766, 1539))

Output:

(30, 30, 30)

The eventual error message:

Traceback (most recent call last):
  File "c:\Users\zyoli\Desktop\scrap_bot\gathering.py", line 14, in <module>
    print(pyautogui.pixel(1766, 1539))
  File "C:\Users\zyoli\AppData\Local\Programs\Python\Python39\lib\site-packages\pyscreeze\__init__.py", line 584, in pixel
    return (r, g, b)
  File "C:\Users\zyoli\AppData\Local\Programs\Python\Python39\lib\contextlib.py", line 124, in __exit__
    next(self.gen)
  File "C:\Users\zyoli\AppData\Local\Programs\Python\Python39\lib\site-packages\pyscreeze\__init__.py", line 113, in __win32_openDC
    raise WindowsError("windll.user32.ReleaseDC failed : return 0")
OSError: windll.user32.ReleaseDC failed : return 0
arun n a
  • 684
  • 9
  • 26
yoel
  • 11
  • 1

1 Answers1

0

I suppose you are switching some windows/app while running the code. Maybe because of the animation(while opening a new window), Pyautogui raises an error. get_pixel from the screen is slow. Maybe this thread can help you: Quickly getting the color of some pixels on the screen in Python on Windows 7

Abhyuday Vaish
  • 2,357
  • 5
  • 11
  • 27