Issue
I'm new to working with python and even more new to working with PyQt4. I created this GUI using QT designer
I converted the file from .ui to a .py file already. The problem I'm running into though is that in my code it is not grabbing the data that the user inputs in the first texteditor box instead I'm getting this error message.
I also looked up the .plainText and tried to use that as well, but I could not get that working either.
import sys
from Calculator import *
class Calc(QtGui.QMainWindow):
def __init__(self, parent = None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.calc_payment, QtCore.SIGNAL('clicked()'), self.calculate)
def calculate(self):
if len(self.ui.Mortgage_value.text())!=0:
q = int(self.ui.Mortgage_value.text())
else:
q = 0
if len(self.ui.tax_rate.text())!=0:
r = int(self.ui.tax_rate.text())
else:
r = 0
if len(self.ui.years.text())!=0:
y = int(self.ui.years.text())
else:
y = 0
taxrate = r / 12
time = y * 12
total = q / ((1 - ((1 + r)**-y))/ r)
#if (calc_payment == 'clicked()'):#test
self.ui.results_window.setText("Monthly Payment: " +int(total))#was str
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = Calc()
myapp.show()
sys.exit(app.exec_())
I appreciate all input that is given.
Thank you.
Solution
QTextEdit does not have a text () method, as it is an editor that can render html, it has 2 methods:
The first returns the plain text, the second in HTML format. in your case, use the first method:
if self.ui.Mortgage_value.toPlainText() != "":
q = int(self.ui.Mortgage_value.toPlainText())
Note: Although I would recommend using QLineEdit instead of QTextEdit since in the case of QTextEdit it has several lines and how you want to convert it to a number can cause problems, besides QLineEdit supports validators like QIntValidator that helps you not to have problems with numbers.
Answered By - eyllanesc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.