edi9999
edi9999

Reputation: 20554

Screenshot of external window in windows in Python

I found this question : Get screenshot on Windows with Python?

to take a screenshot of the full desktop:

import sys
from PyQt4.QtGui import QPixmap, QApplication
from datetime import datetime

date = datetime.now()
filename = date.strftime('%Y-%m-%d_%H-%M-%S.jpg')
app = QApplication(sys.argv)
QPixmap.grabWindow(QApplication.desktop().winId()).save(filename, 'jpg')

However, I would like to take a screenshot of an external window. I have the hwnd of the window I want to take the screenshot off using win32gui.

Upvotes: 1

Views: 698

Answers (1)

ekhumoro
ekhumoro

Reputation: 120608

According to the documentation for winId, the returned value is platform dependent.

So for Windows, it surely must (famous last words), return a hwnd and thus need no further conversion. If so, then try:

    QPixmap.grabWindow(hwnd).save(filename, 'jpg')

(PS: I have actually tested this now on WinXP, and it works okay for me).

Upvotes: 3

Related Questions