Python报错——AttributeError: module 'PyQt5.QtGui' has no attribute 'QApplication'
2017-06-10 10:21
2421 查看
Python报错——AttributeError: module ‘PyQt5.QtGui’ has no attribute ‘QApplication’
初次用Python制作图形界面,遇到了这个问题AttributeError: module ‘PyQt5.QtGui’ has no attribute ‘QApplication’
代码如下:
from PyQt5 import QtCore, QtGui, QtWidgets class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(520, 401) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.quitButton = QtWidgets.QPushButton(self.centralwidget) self.quitButton.setGeometry(QtCore.QRect(350, 260, 91, 51)) self.quitButton.setAutoDefault(False) self.quitButton.setDefault(False) self.quitButton.setFlat(False) self.quitButton.setObjectName("quitButton") MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 520, 23)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) self.quitButton.setText(_translate("MainWindow", "quit")) if __name__ == "__main__": import sys app=QtWidgets.QApplicatio 4000 n(sys.argv) widget=QtWidgets.QWidget() ui=Ui_MainWindow() ui.setupUi(widget) widget.show() sys.exit(app.exec_())
查了一些资料后发现:我用qt designer创建的是一个mainwindow,而不是wideget或者dialog,所以需要把
app=QtWidgets.QApplication(sys.argv)
改成
widget=QtWidgets.QMainWindow()
然后界面就出来啦~~~
相关文章推荐
- Python3异常-AttributeError: module 'sys' has no attribute 'setdefaultencoding'
- AttributeError: module 'tensorflow.python.ops.nn' has no attribute 'legacy_seq2s eq'
- Python2.7 安装mock出现AttributeError: 'module' object has no attribute的解决方法
- Python 2.7.3 AttributeError: 'module' object has no attribute 'urlopen'
- python AttributeError: 'module' object has no attribute 'dumps'解决办法
- python3.6 出现AttributeError: module 'urllib' has no attribute 'urlopen'
- Python3.X出现AttributeError: module 'urllib' has no attribute 'urlopen'错误
- Python 3.x中导入urllib出现AttributeError: module 'urllib' has no attribute 'urlopen'
- python AttributeError: 'module' object has no attribute 'setdefaultencoding'
- AttributeError: module 'requests' has no attribute 'get'”,python中”requests模块“get”属性缺失“的错误该如何解决?
- python 使用scapy包告警WARNING: can't import layer inet: 'module' object has no attribute 'IPPROTO_IPIP'
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- AttributeError: 'module' object has no attribute(转)
- web.py 启动时候出现AttributeError: 'module' object has no attribute 'inet_pton'错误
- AttributeError: 'module' object has no attribute 'Frame' 解决方法
- AttributeError: 'module' object has no attribute 的解决方法
- AttributeError: 'module' object has no attribute 'LabelMap'
- AttributeError: 'module' object has no attribute 'Serial'
- Python基础学习-'module' object has no attribute 'urlopen'解决方法
- AttributeError: 'module' object has no attribute 'HAVE_DECL_MPZ_POWM_SEC'