Im using pyautogui and detecting multiple images through three if statements. But only the top if statement is activated, even though the other if statements should be true according to previous tests
Here is the code:
from pyautogui import *
import pyautogui
import time
import keyboard
import random
import win32api, win32con
while 1:
try:
if (pyautogui.locateOnScreen(r"C:\Users\Daniel Fernando\Desktop\Python\chromeDinosaur\assets\one.png", region=(755,325,120,120), grayscale = True, confidence=0.6) is not None):
print("i see one")
keyboard.send(" ")
elif (pyautogui.locateOnScreen(r"C:\Users\Daniel Fernando\Desktop\Python\chromeDinosaur\assets\three.png", region=(740,325,120,120), grayscale = True, confidence=0.5) is not None):
print("i see three")
keyboard.send(" ")
elif (pyautogui.locateOnScreen(r"C:\Users\Daniel Fernando\Desktop\Python\chromeDinosaur\assets\two.png", region=(740,325,120,120), grayscale = True, confidence=0.5) is not None):
print("i see two")
keyboard.send(" ")
except pyautogui.ImageNotFoundException:
print()
elif(else if) works? If first statement is always true, other ones will never be executed."other if statements"but you don't have otherifbutelif- and this makes difference. You should useifin all places.while Trueinstead ofwhile 1print()in except can be wrong idea - you may have some error but you don't know it - you could display itexcept pyautogui.ImageNotFoundException as es: print(ex)