Can I take a screenshot from desktop or any window with PyQt? How to handle keyPressEvent on desktop?
Thanks.
Advertisement
Answer
Example of how to take a screenshot of the desktop:
JavaScript
x
6
1
import sys
2
from PyQt4.QtGui import QPixmap, QApplication
3
4
app = QApplication(sys.argv)
5
QPixmap.grabWindow(QApplication.desktop().winId()).save('screenshot.jpg', 'jpg')
6
If you want to take a screenshot of a specific window, replace QApplication.desktop()
with the widget you want to take a screenshot of.