Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams from PyQt5.QtGui import QPixmap from PyQt5.QtWidgets import 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') Traceback (most recent call last): File "C:\Python34\Projects\name.py", line 9, in <module> QPixmap.grabWindow(QApplication.desktop().winId()).save(filename, 'jpg') AttributeError: type object 'QPixmap' has no attribute 'grabWindow'

You should use QScreen::grabWindow() instead. QPixmap::grabWindow() is deprecated in Qt 5.0 because :

there might be platform plugins in which window system identifiers (WId) are local to a screen.

grabWindow method is now available in QScreen class.

You need to create QScreen object, initialize it with ex. QtGuiApplication.primaryScreen() and then grab the screen

screen.grabWindow(QApplication.desktop().winId())
import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtGui import QPixmap, QScreen
from datetime import datetime
date = datetime.now()
filename = date.strftime('%Y-%m-%d_%H-%M-%S.jpg')
app = QApplication(sys.argv)
QScreen.grabWindow(app.primaryScreen(), 
QApplication.desktop().winId()).save(filename, 'png')
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.