python - 如何使用 PyQt 抓取桌面屏幕截图?

标签 python pyqt

我可以使用 PyQt 从桌面或任何窗口截取屏幕截图吗?如何在桌面端处理keyPressEvent?

谢谢。

最佳答案

桌面截图示例:

import sys
from PyQt4.QtGui import QPixmap, QApplication

app = QApplication(sys.argv)
QPixmap.grabWindow(QApplication.desktop().winId()).save('screenshot.jpg', 'jpg')

如果您想截取特定窗口的屏幕截图,请将 QApplication.desktop() 替换为您要截取屏幕截图的小部件。

关于python - 如何使用 PyQt 抓取桌面屏幕截图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25056754/

相关文章:

python - 秒表(计时器)不起作用

python - 当没有任何选项卡时,cornerWidget 会消失

python - 索引错误: index 43770 is out of bounds for axis 0 with size 37550

python - 错误类型 :can't pickle _thread. _local 对象

Python 故障处理程序显示错误窗口

javascript - 如何使用 PyQT 在 GUI 中播放 MP3

Python/PyParsing : Difficulty with setResultsName

python - 'PySide2.QtCore.Signal' 对象没有属性 'connect'

python - 对静态属性的引用会产生 NameError

python - pyqt4 QComboBox setEditable(True) - 如何设置MaxLength?