Python 3.x 调用我的脚本时出现PyQt名称错误
我不断地得到这个错误,但根据我的教科书和以前的脚本,应该没有问题Python 3.x 调用我的脚本时出现PyQt名称错误,python-3.x,pyqt4,Python 3.x,Pyqt4,我不断地得到这个错误,但根据我的教科书和以前的脚本,应该没有问题 import sys from PyQt4 import QtCore, QtGui from welcome import * class MyForm(QtGui.QDialog): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.
import sys
from PyQt4 import QtCore, QtGui
from welcome 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_())
**ERROR**
Traceback (most recent call last):
File "C:/Python33/Lib/site-packages/PyQt4/callwelc.py", line 4, in <module>
class MyForm(QtGui.QDialog):
File "C:/Python33/Lib/site-packages/PyQt4/callwelc.py", line 16, in myform
myapp = MyForm()
NameError: name 'MyForm' is not defined
导入系统
从PyQt4导入QtCore、QtGui
从欢迎进口*
类MyForm(QtGui.QDialog):
def uuu init uuu(self,parent=None):
QtGui.QWidget.\uuuuu init\uuuuuu(self,parent)
self.ui=ui_Dialog()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.ClickMeButton、QtCore.SIGNAL('clicked()')、self.dispmessage)
def DISP消息(自我):
self.ui.labelMessage.setText(“Hello”+self.ui.lineUserName.text())
如果名称=“\uuuuu main\uuuuuuuu”:
app=QtGui.QApplication(sys.argv)
myapp=MyForm()
myapp.show()
sys.exit(app.exec_())
**错误**
回溯(最近一次呼叫最后一次):
文件“C:/Python33/Lib/site packages/PyQt4/callwelc.py”,第4行,在
类MyForm(QtGui.QDialog):
文件“C:/Python33/Lib/site packages/PyQt4/callwelc.py”,第16行,myform格式
myapp=MyForm()
NameError:未定义名称“MyForm”
在类定义中有
if\uuu name\uuu
块。这意味着解释器试图在MyForm
类定义完成之前执行它
修正缩进,使if ___;
块位于类定义之外
class MyForm(QtGui.QDialog):
... insides of class here
if __name__=="__main__":
...
将
if\uuuu name\uuuu
块移到类定义之外。