@[TOC]
1 安装
pip install pywinauto -i https://pypi.tuna.tsinghua.edu.cn/simple/
- 官网文档:https://pywinauto.readthedocs.io/en/latest/index.html
- 中文文档:https://www.kancloud.cn/gnefnuy/pywinauto_doc/1193035
2 辅助工具
2.1 inspect.exe的安装
- 官网下载:https://go.microsoft.com/fwlink/?linkid=2250105
3 启动应用程序
- Applicant:作用范围:单个进程
- desktop:作用范围:跨进程
4 具体使用
4.1 开启app
- 开启navicate
from pywinauto import Application app = Application(backend='uia').start(r"D:\tool_soft\navicate\navicate16\Navicat Premium 16\navicat.exe")
- 或者
import pywinauto app = pywinauto.Application(backend='uia').start(r"D:\tool_soft\navicate\navicate16\Navicat Premium 16\navicat.exe")
4.2 连接已经打开的app
- 通过进程id
app = Application(backend='uia').connect(process=23864)
- 通过句柄
app = Application(backend='uia').connect(handle=984832)
4.3 选择窗口
- 通过标题
window = app["Navicat Premium"]
- 通过类名
window = app.TNavicatMainForm
- 查找句柄
handle = findwindows.find_windows(title='Navicat Premium')[0]
- 关闭app
```python
from pywinauto import Application
from pywinauto import findwindows
handle = findwindows.find_windows(title='Navicat Premium')[0]
print(handle)
app = Application().connect(handle=handle)
wind = app['Navicat Premium']
wind.print_control_identifiers()
app.kill()
```