我收到了这个错误,但我不知道自己做错了什么:
>>> runfile('C:/Users/218003107/callphreeqcInput.pyw', wdir=r'C:/Users/218003107')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\218003107\AppData\Local\Continuum\Anaconda\lib\site-
packages\spyderlib\widgets\externalshell\sitecustomize.py", line 580, in runfile
execfile(filename, namespace)
File "C:/Users/218003107/callphreeqcInput.pyw", line 5, in <module>
class MyForm(QtGui.QMainWindow, phreqMDI.Ui_MainWindow):
NameError: name 'phreqMDI' is not defined
>>>"
我正在运行此代码:
import sys
from PyQt4 import QtCore, QtGui
from phreqMDI import *
class MyForm(QtGui.QMainWindow, phreqMDI.Ui_MainWindow):
def __init__(self, parent=None):
super(MyForm,self).__init__(parent)
self.ui=Ui_MainWindow()
self.ui.setupUi(self)
self.connect(wt1,SIGNAL('textChanged()'),wtResult)
self.connect(wt2,SIGNAL('textChanged()'),wtResult)
self.connect(wt3,SIGNAL('textChanged()'),wtResult)
self.connect(wt4,SIGNAL('textChanged()'),wtResult)
def wtResult(self):
if len(self.ui.wt1.text())!=0:
a=float(self.ui.wt1.text())
else:
a=0
if len(self.ui.wt2.text())!=0:
b=float(self.ui.wt2.text())
else:
b=0
if len(self.ui.wt3.text())!=0:
c=float(self.ui.wt3.text())
else:
c=0
if len(self.ui.wt4.text())!=0:
c=float(self.ui.wt4.text())
else:
d=0
sum=a+b+c+d
self.ui.wt_total.setText(str(sum))
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
=MyForm()
myapp.show()
app.exec_()
以下是使用Qt Designer创建的ui文件的前几行(未显示所有500行),并使用pyuic4转换为.py(这很好):
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(800, 677)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
我在这里做错了什么?
答案 0 :(得分:0)
由于您已从phreqMDI
导入所有内容,因此代码应为:
from phreqMDI import *
class MyForm(QtGui.QMainWindow, Ui_MainWindow):
或
import phreqMDI
class MyForm(QtGui.QMainWindow, phreqMDI.Ui_MainWindow):