我在PyCharm中有以下代码。
import sys
from PyQt5 import QtGui
app = QtGui.QGuiApplication(sys.argv)
w = QtGui.QWidget()
w.show()
status = app.exec_()
sys.exit(status)
当我试图运行这段代码时,我得到以下错误:
C:Python34python.exe C:/Users/IBM_ADMIN/Desktop/Heydar/aaaa.py
Traceback (most recent call last):
File "C:/Users/IBM_ADMIN/Desktop/Heydar/aaaa.py", line 5, in <module>
w = QtGui.QWidget()
AttributeError: 'module' object has no attribute 'QWidget'
Process finished with exit code 1
有人能帮忙吗?
PyCharm由于某些原因无法识别QWidget()
PyQt4和PyQt5有不同的实现。你得到这个错误是因为它是:
QtWidgets.QWidget()
根据文档:
PyQt4的QtGui模块被拆分为PyQt5的QtGui, QtPrintSupport和QtWidgets模块