Python - 当img弹出时点击某处

时间:2018-02-08 00:02:13

标签: python pyautogui

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

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
你有什么主意吗?谢谢

1 个答案:

答案 0 :(得分:0)

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

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
相关问题