How to set condition to True?

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

def imageFind(image,g,double):
    a = 0
    b = 0
    while(a==0 and b==0):
            a,b = p.locateCenterOnScreen(image,grayscale=g)
        except TypeError:

    if double == True:

    return a,b

counter = 1
while counter == 1:
    image_find = imageFind("Edge.png",False,False)
    if image_find == 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?

Thank you.

>Solution :

imageFind does not return a single bool values but instead returns a tuple. your True condition is when both a and b are non zero so change your if image_find == True: to if all(image_find):

all() returns True only if all values are True or non zero

Leave a Reply