未找到 PyAutoGUI 图像

问题描述 投票:0回答:1

我正在尝试在我的项目目录中搜索图像。确保程序正在使用工作目录,但它仍然给我一个图像未找到的异常。

def joinListenerGo():
    print("Join Listener Starting please have ark open.")
    join_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'JoinUpdated.png')
    someonejoined = pyautogui.locateOnScreen('joiner.png', grayscale=False, confidence=0.8)
    if someonejoined != None:
        print("Someone Joined")
        pyautogui.click(someonejoined)
        pyautogui.write("Someone joined the ark server")

错误:

Traceback (most recent call last):
  File "C:\Users\Hades\AppData\Local\Programs\Python\Python312\Lib\tkinter\__init__.py", line 1967, in __call__
    return self.func(*args)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\Hades\PycharmProjects\AlbionGathering\.venv\Lib\site-packages\customtkinter\windows\widgets\ctk_switch.py", line 413, in toggle
    self._command()
  File "C:\Users\Hades\PycharmProjects\AlbionGathering\main.py", line 58, in <lambda>
    joinerOn = CTkSwitch(master=joiner, text="Join Listener", command=lambda: joinListenerGo())
                                                                              ^^^^^^^^^^^^^^^^
  File "C:\Users\Hades\PycharmProjects\AlbionGathering\main.py", line 65, in joinListenerGo
    someonejoined = pyautogui.locateOnScreen('joiner.png', grayscale=False, confidence=0.8)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Hades\PycharmProjects\AlbionGathering\.venv\Lib\site-packages\pyautogui\__init__.py", line 174, in wrapper
    raise ImageNotFoundException  # Raise PyAutoGUI's ImageNotFoundException.
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pyautogui.ImageNotFoundException

确保它正在使用图像的工作目录(确实如此)我希望它能够看到图像,但它不能。

python-3.x pyautogui
1个回答
0
投票

经过更多测试后,我能够使用带有 try catch 的 while True 语句使其工作

© www.soinside.com 2019 - 2024. All rights reserved.