尝试调用我的应用程序时不断收到此错误
Posted
技术标签:
【中文标题】尝试调用我的应用程序时不断收到此错误【英文标题】:I keep getting this error when trying to call my applications 【发布时间】:2017-04-19 22:25:45 【问题描述】:我构建的所有应用程序都会出现此错误。我是 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'
【问题讨论】:
【参考方案1】:从 Qt5 开始,QDialog
位于 QtWidgets
模块中,而不是 QtGui
。
【讨论】:
以上是关于尝试调用我的应用程序时不断收到此错误的主要内容,如果未能解决你的问题,请参考以下文章
我正在尝试在我的程序中本地解码 JSON 文件,但不断收到错误
尝试接受 Android Studio 许可证时,我不断收到此错误“java.lang.NoClassDefFoundError”
不断收到“在 YourAppName 中打开此页面?”的警报视图消息?尝试从 Safari 启动应用程序时