Python - 当 img 弹出时点击某处

Python - Click somewhere when the img pop up

我想写一个程序,图片随时弹出,动作是关闭图片,而不是点击图片。我对代码有一些想法,但没有成功:(图像没有弹出,但仍然等待 1 秒并单击右上角的 conner ..)

import pyautogui, time
while ture:    pyautogui.click(pyautogui.center(pyautogui.locateOnScreen(r'C:\Users\Lawrence\Desktop\PyTest\image.png')))  
time.sleep(1)   #I want to check image every sec
break
pyautogui.click(1880,15)   # after checking the screen for every sec, the image popup, and click top right conner to close it, finish
你有什么主意吗?谢谢

试试这个。你打破得太早了,点击了错误的东西。

import pyautogui, time
while True:
    #I want to check image every sec
    time.sleep(.1) #put time interval for checking here
    if pyautogui.locateOnScreen(r'C:\Users\Lawrence\Desktop\PyTest\image.png'):
       pyautogui.click(1880,15)  
       break