Search code examples
python-3.xpywinautopyautogui

How to control windows in windows 10 with python3


I am looking for a good way to get window information to find and close them programmatically.

i have been using pywinauto and pyautogui. brining all of my knowledge from autoit.

Using python3 autoit has not been working.

From Python3 we hope to accomplish: Here is the AutoIT command to translate to python3

If WinExists("WindowName") then
    WinClose("WindowName")

Solution

  • Thank you for all your help everyone, I seem to have found a good solution. Hopefully this will help someone else as well!

    This connects the application to Pywinauto:

    import pywinauto as pwa
    app = pwa.application.Application(backend="uia")
    app.connect(path='AppName.exe')
    

    Here we are creating a dialog for the app window and specifying a name reference.

    dlg = app.window(title_re=".*AppName.*")
    

    In this area, we are calling the window, and wait for it to be ready. Then we are going to close the window.

    dlg.child_window(title="WindowName", control_type="Window").wait('ready', timeout=10):
    dlg.child_window(title="WindowName", control_type="Window").close()
    print("Window is closed")