【发布时间】:2016-04-29 19:16:34
【问题描述】:
系统:15.10 (Wily Werewolf) x64
代码:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'test.ui'
#
# Created by: PyQt5 UI code generator 5.5.1
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(400, 300)
self.pushButton = QtWidgets.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(120, 120, 85, 26))
self.pushButton.setObjectName("pushButton")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.pushButton.setText(_translate("Form", "PushButton"))
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
ex = Ui_Form()
ex.show()
sys.exit(app.exec_())
我收到以下错误:
app = QtGui.QApplication(sys.argv)
AttributeError: 'module' object has no attribute 'QApplication'
基本上,我用 Qt5 设计了 GUI,然后使用了 pyuic5。我已经安装了 PyQt5,不确定安装是否按预期进行。
界面设计:
我们将不胜感激。
【问题讨论】:
-
这个:
dir(QtGui)给你什么? -
我刚刚更新了帖子以供进一步参考。
-
这段代码有几个问题:
QApplication在QWidgets中,缺少import sys语句,Ui_Form可能应该继承一个Qt 类QWidget?,ex.setupUi(ex)必须在ex.show()之前调用。 -
让我再试一次。我在练习中使用过。