Python PyAutoGui pixelMatchesColor 引发 windll

在尝试查看屏幕上的像素是否与 RGB 颜色匹配时遇到问题。但是,即使经过调整,我也无法获得任何好的结果。我在网上查找并尝试了不同的解决方案,但没有运气。


Exception in thread Thread-2:

Traceback (most recent call last):

  File "C:\Python38\lib\threading.py", line 932, in _bootstrap_inner

    self.run()

  File "C:\Python38\lib\threading.py", line 870, in run

    self._target(*self._args, **self._kwargs)

  File "C:\Python38\lib\site-packages\keyboard\_generic.py", line 58, in process

    if self.pre_process_event(event):

  File "C:\Python38\lib\site-packages\keyboard\__init__.py", line 218, in pre_process_event

    callback(event)

  File "C:\Python38\lib\site-packages\keyboard\__init__.py", line 649, in <lambda>

    handler = lambda e: (event_type == KEY_DOWN and e.event_type == KEY_UP and e.scan_code in _logically_pressed_keys) or (event_type == e.event_type and callback())

  File "main.py", line 101, in bomb_timer

    pix = pyautogui.pixelMatchesColor(959, 83, (169, 0, 0), tolerance=61)

  File "C:\Python38\lib\site-packages\pyscreeze\__init__.py", line 559, in pixelMatchesColor

    pix = pixel(x, y)

  File "C:\Python38\lib\site-packages\pyscreeze\__init__.py", line 584, in pixel

    return (r, g, b)

  File "C:\Python38\lib\contextlib.py", line 120, in __exit__

    next(self.gen)

  File "C:\Python38\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

我的代码:


def clock_timer():

    clock = pyautogui.locateCenterOnScreen('assets/clock2.png', grayscale=True, confidence=0.5, region=(920,10, 90, 90))

    print(Style.RESET_ALL + "[" + Fore.RED + "zVal" + Style.RESET_ALL + "]" + Fore.RED + " Waiting for clock...")

    while clock == None:

        clock1 = pyautogui.locateCenterOnScreen('assets/clock2.png', grayscale=True, confidence=0.5, region=(920,10, 90, 90))

        pix = pyautogui.pixelMatchesColor(959, 83, (169, 0, 0), tolerance=61) #PART THAT DOESNT WORK

        if clock1 != None and pix == True:

            clock = "Stop loop"


皈依舞
浏览 250回答 2
2回答

jeck猫

找不到发生这种情况的确切原因,但解决方法是删除我所有的 Python 版本(3.78 和 3.83),然后我只重新安装 3.83。这解决了问题。希望这可以帮助其他人解决这个问题。

肥皂起泡泡

可能的解决方案:从 Python 3.8 降级到 3.7重新安装 Python在 python 解释器/cmd >> python 中尝试
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python