前言
pywinauto 对窗口和控件截图 capture_as_image()
窗口截图
对连接的窗口截图
from pywinauto import Application
app = Application('uia').start("notepad.exe")
win = app.window(title_re="无标题 - 记事本")
# 对窗口截图
win.capture_as_image().save('not.png')
运行后提示
Traceback (most recent call last):
File "D:/demo/untitled_gui/daa/x5.py", line 8, in <module>
win.capture_as_image().save('not.png')
AttributeError: 'NoneType' object has no attribute 'save'
PIL does not seem to be installed. PIL is required for capture_as_image
提示PIL 没安装,先安装环境
pip install Pillow
但是截图会有其它窗口的背景会叠加
对控件截图
对 MenuBar 控件截图
from pywinauto import Application
app = Application('uia').start("notepad.exe")
win = app.window(title_re="无标题 - 记事本")
# 对窗口截图
# win.capture_as_image().save('not.png')
print(win.print_ctrl_ids())
menu = win.child_window(title="应用程序", auto_id="MenuBar", control_type="MenuBar")
menu.capture_as_image().save('m.png')
标签:11,控件,截图,capture,win,image,save
From: https://www.cnblogs.com/yoyoketang/p/17653741.html