我正在尝试将我的代码从PyQt4转换为PyQt5,但我收到了错误。
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:\Python34\Projects\name.py", line 7, in <module>
from PyQt5.QtGui import QApplication, QPixmap
ImportError: cannot import name 'QApplication'
答案 0 :(得分:32)
QApplication
位于PyQt5.QtWidgets
模块中。所以你的import语句应该是:
from PyQt5.QtWidgets import QApplication
答案 1 :(得分:14)