How do I locate cursor on somethings with an AI?

I'm trying to find an image on the screen, and then I hover and click on the image with the code. Code can see it, but it can't find it.

from pyautogui import * 
import pyautogui 
import time 
import keyboard 
import random
import win32api, win32con

time.sleep(2)

def click(x,y):
    win32api.SetCursorPos((x,y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0)

while keyboard.is_pressed('q') == False:
            flag = 0
            pic = pyautogui.screenshot()

            width, height = pic.size

            for x in range(0, width, 1):
                for y in range(0, height, 1):
                    if pyautogui.locateOnScreen('stickman.png', confidence=0.4) != None:
                        flag = 1
                        click(x, y)
                        time.sleep(0.05)
                        break

                if flag == 1:
                    break
How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum