1. Operating program window
1. Use the name or class name of the program window to locate the window or its sub-windows
window = app['test001.txt - 记事本']
from pywinauto.application import Application
# 通过窗口句柄连接已经启动的记事本程序,记事本的窗口句柄NativeWindowHandle为2564730
handle = 2564730
app = Application(backend='uia').connect(handle=handle)
# 通过窗口title指定待操作窗口
window = app['test001.txt - 记事本']
# 控台输出该窗口下所有的子窗口的类名、标题、位置、控制类型等信息
window.print_control_identifiers()
2. Locate by specifying the name or class name of the program window
window = app.window(title='test001.txt - 记事本', class_name='Notepad')
3. If the title name is too long, use the title_re regular rule to bind and locate
window = app.window(title_re='.*est001.*')
4. Request the positioning of the topmost window (not necessarily the expected window)
window = app.top_window()
from pywinauto.application import Application
# 通过窗口句柄连接已经启动的记事本程序,记事本的窗口句柄NativeWindowHandle为2564730
handle = 2564730
app = Application(backend='uia').connect(handle=handle)
# 请求最顶部窗口(也不一定是预期的窗口)
window = app.top_window()
# 输出记事本窗口标题
main_title = window.get_properties()['texts'][0]
print(main_title)