#🔒 I am a error with image location with pyautogui

12 messages · Page 1 of 1 (latest)

wispy hemlock
#

I am working on a bot for squid game. If it finds a green it walk if red releases, but it keeps giving error
error:
Traceback (most recent call last):
File "c:\Users\prived\Desktop\Python\Squid game\Squid_game.py", line 8, in <module>
if pyautogui.locateOnScreen(r'C:\Users\prived\Desktop\Python\Squid game\green.png'):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\Programming\Python\Lib\site-packages\pyautogui_init_.py", line 174, in wrapper
raise ImageNotFoundException # Raise PyAutoGUI's ImageNotFoundException.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pyautogui.ImageNotFoundException

code:

import pyautogui
import time
import keyboard

time.sleep(2)

while True:
    if pyautogui.locateOnScreen(r'C:\Users\cyanr\Desktop\Python\Squid game\green.png'):
        keyboard.press('w')
    elif pyautogui.locateOnScreen(r'C:\Users\cyanr\Desktop\Python\Squid game\red.png'):
        keyboard.release('w')
    else:
        time.sleep()
    
    if keyboard.is_pressed('q'):
        exit()
zealous isleBOT
#

@wispy hemlock

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

cosmic shuttle
#

Oh, when the image is not found it resulted in a exception

#

So you'll need to use try..except

wispy hemlock
#

Oh

cosmic shuttle
#
try:
   #try to detect the image
except ImageNotFoundException:
   #image not found 
#

Repeat this for both images

wispy hemlock
#

Oh oké

#

Let me try to put it in

#

Thanks

zealous isleBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.