[Python] Pyautogui only activating when it is the first if statement

Discussão em 'Python' iniciado por Stack, Maio 5, 2025.

  1. Stack

    Stack Membro Participativo

    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:

    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()

    Continue reading...

Compartilhe esta Página