pywinauto UI Automation Windows GUI Automation

Automating Windows GUI with pywinauto and UI Automation

A useful library for automating Windows and software interface GUIs is Microsoft UI Automation (UIA). pywinauto makes UI automation available as a library from the Python language, allowing similar Windows automation.

Shou Arisaka
3 min read
Oct 17, 2025

A useful library for automating Windows and software interface GUIs is Microsoft UI Automation (UIA). pywinauto makes UI automation available as a library from the Python language, allowing similar Windows automation.

Github:

pywinauto/pywinauto: Windows GUI Automation with Python (based on text properties)

Documentation:

What is pywinauto — pywinauto 0.6.8 documentation

When it comes to Windows automation, autohotkey comes to mind, but Autohotkey is mainly for keyboard and mouse automation, or adding hotkeys/shortcut keys, and is not suitable for detailed automation processing of launched .NET framework-based software or graphical user interfaces.

For other cases, if you’re automating Excel, VBA is used, and for automating browsers/web pages like Chrome or Firefox, libraries like selenium, puppeteer, or playwright are suitable.

Image

Installation

If python is not yet installed, use chocolatey to install python.

choco list --localonly
choco install python --version=3.6.7

An overview of what chocolatey is and how to install it is introduced below.

Installing chocolatey on Windows 11

Install virtualenv. Then create a virtual environment with virtualenv.

C:\Python36\python.exe -m pip install virtualenv
C:\Python36\python.exe -m virtualenv venv3.6

Enter the virtualenv virtual environment and install the pywinauto library.

. .\venv3.6\Scripts\activate
pip install -U pywinauto

Running pywinauto

Sample code for pywinauto looks like this: When you run the following python script, notepad.exe (Notepad) will open, and the help page and about page will automatically open from the menu.

Note that the code below assumes the Windows system language is English, so if it’s a Japanese system, you may need to change “Help->About Notepad” or similar.

from pywinauto.application import Application
app = Application().start("notepad.exe")

app.UntitledNotepad.menu_select("Help->About Notepad")
app.AboutNotepad.OK.click()
app.UntitledNotepad.Edit.type_keys("pywinauto Works!", with_spaces = True)

Errors

Below is how to deal with errors that occur.

The following error may occur during pywinauto execution:

_argtypes_ passes a union by value, which is unsupported

The cause appears to be when the python version is 3.8 or higher.

As a solution, downgrade the python version to 3.7.4 or lower. In the installation above, we specified version 3.6.7 for python installation with choco install python —version=3.6.7. It seems to work at least with 3.6.7.

downgrade python to 3.7.4

tkinter - Python Error - TypeError: item 1 in argtypes passes a union by value, which is unsupported - Stack Overflow

Reference pages:

Share this article

Shou Arisaka Oct 17, 2025

🔗 Copy Links