PyQt5 Python 3 Qline编辑计算加/减数字

时间:2018-05-26 18:35:46

标签: python python-3.x pyqt pyqt5

我的程序不会添加或减去Qline编辑的输入 它打印输入彼此相邻! 尝试了一切并搜索了互联网。

出来是1111,应该是22。

提前谢谢。

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_())

1 个答案:

答案 0 :(得分:1)

调用QLineEdit.text()会将QLineEdit中的文本作为字符串返回。您必须将其转换为int才能将它们添加到一起。

尝试:

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