-1

My program does not add or subtract the inputs from the Qline edit It prints the inputs next to each other ! Have tried everything and searched internet.

Out come is 1111, should be 22.

Thx in advance.

import sys
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtWidgets import QMainWindow, QWidget, QLabel, QLineEdit
from PyQt5.QtWidgets import QPushButton, QFrame, QCheckBox
from PyQt5.QtCore import QSize
from PyQt5.QtCore import QTimer
from PyQt5.QtGui import QDoubleValidator, QIntValidator

class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)

        self.setMinimumSize(QSize(550, 400))       #     Hor    verti
        self.move(1350, 600)
    self.setWindowTitle("Mantas Crypto platform Cryptopia PIRL BTC")

    self.buyamountsettinglabel = QLabel(self)
    self.buyamountsettinglabel.setText('Buy Amount')
    self.buyamountsettinglabel.move(300, 155)
    self.buyamountsetting = QLineEdit(self)
    self.buyamountsetting.move(440, 160)
    self.buyamountsetting.resize(70, 20)
    self.buyamountsetting.setText('11')
    self.sellamountsettinglabel = QLabel(self)
    self.sellamountsettinglabel.setText('Sell Amount')
    self.sellamountsettinglabel.move(300, 180)
    self.sellamountsetting = QLineEdit(self)
    self.sellamountsetting.move(440, 185)
    self.sellamountsetting.resize(70, 20)
    self.sellamountsetting.setText('11')

    print(self.buyamountsetting.text())

    test = self.buyamountsetting.text() + self.sellamountsetting.text()
    print(test)




if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    mainWin = MainWindow()
    mainWin.show()
    sys.exit(app.exec_())
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • change `test = self.buyamountsetting.text() + self.sellamountsetting.text()` to `test = int(self.buyamountsetting.text()) + int(self.sellamountsetting.text())` – eyllanesc May 26 '18 at 18:41
  • The sum in string is concatenation, you must convert it to float or int – eyllanesc May 26 '18 at 18:42

1 Answers1

1

Calling QLineEdit.text() returns the text that is in the QLineEdit as a string. You must convert it to an int to be able to add them together.

Try:

test = int(self.buyamountsetting.text()) + int(self.sellamountsetting.text())
MalloyDelacroix
  • 2,193
  • 1
  • 13
  • 17