I’ve created a program that uses pyautogui to locate an image stored in the directory and click on it when it finds it. So when it see’s ‘Microsoft Edge’ it instantly clicks on it. I have this running on a loop and want to stop the loop when it finds the image. This is really important for me – but I want the loop to stop even before it clicks it, so while ‘double’ is false, as you will see below.
Here it is:
import pyautogui as p import time import random import os import pygame from hashlib import sha256 def search(query): p.hotkey("ctrl","e") time.sleep(.1) p.write(query) p.press("enter") time.sleep(.67) def imageFind(image,g,double): a = 0 b = 0 while(a==0 and b==0): try: a,b = p.locateCenterOnScreen(image,grayscale=g) except TypeError: pass if double == True: p.doubleClick(a,b) else: p.click(a,b) return a,b #p.hotkey("win","d") counter = 1 while counter == 1: image_find = imageFind("Edge.png",False,False) if image_find == True: imageFind("Edge.png",False,True) counter = 0
I’ve done ‘if image_find == True’ but it doesn’t work as the loop continues.
So how do I code this so that when it finds the image, it stops. How do confirm that what it finds is a True statement?
imageFind does not return a single bool values but instead returns a tuple. your
True condition is when both
b are non zero so change your
if image_find == True: to
True only if all values are
True or non zero