New to QtDesigner and PyQt and trying to get my first simple application going. (The user enters anywhere from one to three values in LineEdits and the sum is put in a fourth LineEdit). I created the GUI (simpleAdder1.py) with Qt Designer and then wrote the following code (callsimpleAdder1.pyw). Unfortunately it's not running and code analysis suggests a problem at the 'from simpleAdder1 import *' line. The problem is ...."from simpleAdder1 import * ,used, unable to detect undefined names'
I originally thought it was a path problem. But simpleAdder1.py is in the same directory as callsimpleadder1.pyw. I also copied simpleAdder1 into one of the paths that Python checks and that didn't help.
Where am I going wrong ? What names are undefined ? How do I fix this ?
import sys
from simpleAdder1 import *
class MyForm(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui=Ui_Dialog()
self.ui.setupUi(self)
def on_v1Input_textChanged(self):
self.ui.calcResult()
def on_v2Input_textChanged(self):
self.ui.calcResult()
def on_v3Input_textChanged(self):
self.ui.calcResult()
def calcResult(self):
if len(self.ui.v1Input.txt())!=0:
a=float(self.ui.v1Input.txt())
else:
a=0
if len(self.ui.v2Input.txt())!=0:
b=float(self.ui.v2Input.txt())
else:
b=0
if len(self.ui.v3Input.txt())!=0:
c=float(self.ui.v1Input.txt())
else:
c=0
sum=a+b+c
self.ui.calc_result.setText(+str(sum))
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp=MyForm()
myapp.show
app.exec_()
The code for the GUI (simpleAdder1) is as follows:
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_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(673, 565)
self.v1Input = QtGui.QLineEdit(Dialog)
self.v1Input.setGeometry(QtCore.QRect(50, 70, 71, 20))
self.v1Input.setObjectName(_fromUtf8("v1Input"))
self.v2Input = QtGui.QLineEdit(Dialog)
self.v2Input.setGeometry(QtCore.QRect(150, 70, 71, 20))
self.v2Input.setObjectName(_fromUtf8("v2Input"))
self.v3Input = QtGui.QLineEdit(Dialog)
self.v3Input.setGeometry(QtCore.QRect(250, 70, 71, 20))
self.v3Input.setObjectName(_fromUtf8("v3Input"))
self.calc_result = QtGui.QLineEdit(Dialog)
self.calc_result.setGeometry(QtCore.QRect(420, 70, 113, 20))
self.calc_result.setObjectName(_fromUtf8("calc_result"))
self.label = QtGui.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(60, 50, 46, 13))
self.label.setObjectName(_fromUtf8("label"))
self.label_2 = QtGui.QLabel(Dialog)
self.label_2.setGeometry(QtCore.QRect(160, 50, 46, 13))
self.label_2.setObjectName(_fromUtf8("label_2"))
self.label_3 = QtGui.QLabel(Dialog)
self.label_3.setGeometry(QtCore.QRect(260, 50, 46, 13))
self.label_3.setObjectName(_fromUtf8("label_3"))
self.label_4 = QtGui.QLabel(Dialog)
self.label_4.setGeometry(QtCore.QRect(450, 50, 46, 13))
self.label_4.setObjectName(_fromUtf8("label_4"))
self.pushButton = QtGui.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(200, 230, 75, 23))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.retranslateUi(Dialog)
QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), self.v1Input.clear)
QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), self.v2Input.clear)
QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), self.v3Input.clear)
QtCore.QMetaObject.connectSlotsByName(Dialog)
#QtCore.QObject.connect(self.v1Input,QtCore.SIGNAL("textChanged"),self.calcResult)
#QtCore.QObject.connect(self.v2Input,QtCore.SIGNAL("textChanged"),self.calcResult)
#QtCore.QObject.connect(self.v3Input,QtCore.SIGNAL("textChanged"),self.calcResult)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
self.label.setText(_translate("Dialog", "Val 1", None))
self.label_2.setText(_translate("Dialog", "Val 2", None))
self.label_3.setText(_translate("Dialog", "Val 3", None))
self.label_4.setText(_translate("Dialog", "Result", None))
self.pushButton.setText(_translate("Dialog", "Clear Inputs", None))
OK, I think I (maybe) understand your problem.
Unfortunately it's not running and code analysis suggests a problem at the 'from simpleAdder1 import *' line. The problem is ...."from simpleAdder1 import * ,used, unable to detect undefined names'
I see your code the problem widget can't show isn't this error I think error this your path file. But, I use PyDev 2.8.2 on Eclipse Kepler Service Release 1, It have (little) warning unused import like this,
Unused in wild import: QtCore
Found at: simpleAdder1
Then, I suggest to use "used import" only, like this;
from simpleAdder1 import Ui_Dialog, QtGui
And what is going wrong your GUI ? It's because this line in main;
myapp.show
To solve problem, please "Call function" (In old isn't call function anything) like this;
myapp.show()
Regards,