PyQt5 cannot import name 'QApplication'

Question:

I am trying convert my code from PyQt4 to PyQt5 but I am getting errors.

from PyQt5.QtGui import QApplication, QPixmap
desktop = QApplication.desktop()
QPixmap.grabWindow(desktop.screen().winId()).save("screen.png", "PNG")


3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)]
Traceback (most recent call last):
  File "C:Python34Projectsname.py", line 7, in <module>
    from PyQt5.QtGui import QApplication, QPixmap
ImportError: cannot import name 'QApplication'
Asked By: Arthur Yakovlev

||

Answers:

QApplication is in PyQt5.QtWidgets.

So it should be

from PyQt5.QtWidgets import QApplication
Answered By: azalea

QApplication is located in PyQt5.QtWidgets module. So your import statement should be:

from PyQt5.QtWidgets import QApplication
Answered By: styvane
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.