So I am trying to make this so that it will print “hello” until the ‘logout’ image is found. But unless the image is immidietly on the screen it will just error out. I have also tried iterations but that kind of doesnt work because basically I want this to be just constantly checking to see if this image is present every second or so. I am super new and bad at this so im sure its something easy but I cannot seem to find it.
`import pyautogui as pt
import time as t
import random as rand
import cv2
def check_logout():
logout_image = pt.locateCenterOnScreen(‘logout.PNG’, confidence=.9)
if logout_image is not None:
print(“Logout image found. Exiting…”)
exit()
else:
print(“Hello”)
t.sleep(1)
while True:
check_logout()`
I am expecting it to constantly check and once the image is seen then to exit the script.
Tyler Trager is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.