首页 > 解决方案 > 我在制作 pyautogui 程序时遇到了 windows 错误和 os 错误

问题描述

当我运行下面的代码时,我得到了这个错误:

文件“e:\pranil\python\doing shit with python\automating dino game.py”,第 12 行,在 if auto.pixelMatchesColor(i,j, (83, 83, 83)) 中:文件“C:\Users\ Pranil.DESKTOP-TLQKP4G.000\AppData\Local\Programs\Python\Python38\lib\site-packages\pyscreez__init__.py",第 559 行,在 pixelMatchesColor pix = pixel(x, y) 文件“C:\Users\Pranil .DESKTOP-TLQKP4G.000\AppData\Local\Programs\Python\Python38\lib\site-packages\pyscreez__init__.py”,第 584 行,以像素返回 (r, g, b) 文件“C:\Users\Pranil. DESKTOP-TLQKP4G.000\AppData\Local\Programs\Python\Python38\lib\contextlib.py",第 120 行,退出 next(self.gen) 文件“C:\Users\Pranil.DESKTOP-TLQKP4G.000\AppData\Local\Programs\Python\Python38\lib\site-packages\pyscreez__init__.py”,第 113 行,在 __win32_openDC 中引发 WindowsError( “windll.user32.ReleaseDC 失败:返回 0”)OSError:windll.user32.ReleaseDC 失败:返回 0

import pyautogui as auto
from PIL import Image, ImageColor
import time
import keyboard
auto.FAILSAFE = False
time.sleep(2)
# print(auto.position())
while True:
    sshot = auto.screenshot()
    for j in range(510, 514):
        for i in range(316, 350):
            if auto.pixelMatchesColor(i,j, (83, 83, 83)):
                auto.press('up')
    if keyboard.is_pressed('q'):
        break

标签: pythonpython-3.xwindowspyautogui

解决方案


我建议将你的 python 从 3.8 降级到 3.7,因为它为我解决了它。


推荐阅读