0 环境
- Python 3.12.1
- PyQt6 6.6.1 ' pip install PyQt6 '
PyQt6-Qt6 6.6.1 默认安装
PyQt6-sip 13.6.0 默认安装
1 简介
屏幕截图的方法: 使用 【PyQt6】的 QScreen.grabWindow() 方法
def grabWindow(self, WId=0, x, y, width, height) -> QPixmap:
WId: 窗口系统标识符, 默认 0 表示 屏幕将被抓取
偏移: x, y,
大小: width, height
如果想要全屏截图, 连参数都不需要写
screen = QApplication.primaryScreen()
pixmap = screen.grabWindow()
pixmap.save('123.png') # 可以直接保存为文件, qt 会根据扩展名 保存成不同的格式
2 QScreen 类
2.1 获取 QScreen 的对象
QScreen 不能被实例化,只能从 QGuiApplication 来获取
class QGuiApplication(QtCore.QCoreApplication):
...
@staticmethod
def screens()</