asweigart / pyautogui

A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
BSD 3-Clause "New" or "Revised" License
10.45k stars 1.26k forks source link

Loop can only find 1 window #670

Open itsmichaelk opened 2 years ago

itsmichaelk commented 2 years ago

Hello everyone,

I have this code:

import pyautogui as pg

while True:
    window = pg.locateOnScreen("erteilen.png", minSearchTime=3, confidence=0.9)
    try:
        print(window)
        pg.click(x=window.left+int(window.width/2), y=window.top+int(window.height/2), clicks=3)
    except Exception as e:
        break

It will click on the found window, then the same window opens again, but the script won't locate it again. When I click in the command window, it seems like pyautogui refreshes it's screen and then finds the window.

Can someone help me? Thanks in advance!

Michael