此错误不断出现在我构建的所有应用程序上。我是pyqt的新手。
代码:
from PyQt5 import QtCore, QtGui, QtWidgets
try:
_fromUtf8 = QtCore.Qstring.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(400, 195)
self.ClickMeButton = QtWidgets.QPushButton(Dialog)
self.ClickMeButton.setGeometry(QtCore.QRect(130, 160, 75, 23))
self.ClickMeButton.setObjectName("ClickMeButton")
self.lineUserName = QtWidgets.QLineEdit(Dialog)
self.lineUserName.setGeometry(QtCore.QRect(150, 40, 211, 20))
self.lineUserName.setObjectName("lineUserName")
self.labelEnterName = QtWidgets.QLabel(Dialog)
self.labelEnterName.setGeometry(QtCore.QRect(30, 40, 111, 16))
font = QtGui.QFont()
font.setPointSize(10)
font.setBold(True)
font.setWeight(75)
self.labelEnterName.setFont(font)
self.labelEnterName.setObjectName("labelEnterName")
self.labelMessage = QtWidgets.QLabel(Dialog)
self.labelMessage.setGeometry(QtCore.QRect(20, 70, 341, 81))
self.labelMessage.setText("")
self.labelMessage.setObjectName("labelMessage")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.ClickMeButton.setText(_translate("Dialog", "&ClickMe"))
self.labelEnterName.setText(_translate("Dialog", "Enter your name."))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
***call app***
import sys
from welcomemsg import *
class MyForm(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Dialog()
self.ui.setupUi(self)
QtCore.Qobject.connect(self.ui.ClickMeButton, QtCore.SIGNAL('clicked()'),self.dispmessage)
def dispmessage(self):
self.ui.labelmessage.setText("Hello "+ self.ui.lineUserName.text())
if __name__=="__main__":
app = QtGui.QApplication(sys.argv)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())
错误
class MyForm(QtGui.QDialog):
AttributeError: module 'PyQt5.QtGui' has no attribute 'QDialog'
答案 0 :(得分:0)
自Qt5起,QDialog
位于QtWidgets
模块中,而不是QtGui
。