Python 我想使用PyQt5制作计算器机器人,但我遇到了一个错误

Python 我想使用PyQt5制作计算器机器人,但我遇到了一个错误,python,pyqt5,typeerror,python-3.6,Python,Pyqt5,Typeerror,Python 3.6,我想用PyQt5制作计算器机器人,我得到了这个错误。 你能帮我吗 另外,我在PyQt5乞讨 我的错误是: TypeError: setText(self, str): argument 1 has unexpected type 'int' 我的代码是: class Dialog(QDialog): def __init__(self): QDialog.__init__(self) self.dialog = QComboBox() s

我想用PyQt5制作计算器机器人,我得到了这个错误。 你能帮我吗

另外,我在PyQt5乞讨

我的错误是:

TypeError: setText(self, str): argument 1 has unexpected type 'int'
我的代码是:

class Dialog(QDialog):
    def __init__(self):
        QDialog.__init__(self)
        self.dialog = QComboBox()
        self.lbl = QLabel("Choose Gas Name:")
        self.but = QPushButton("Calculate")
        self.litre = QLineEdit(self)
        self.regular = QLabel("Regular >>> "+str(2.27))
        self.euro_reg = QLabel("Euro Regular >>> "+str(2.33))
        self.diesel = QLabel("Diesel >>> "+str(2.39))
        self.calculated = QLabel("")
        self.init_ui()
    def init_ui(self):
        layout = QVBoxLayout()
        layout.addWidget(self.regular)
        layout.addWidget(self.euro_reg)
        layout.addWidget(self.diesel)
        layout.addWidget(self.litre)
        layout.addWidget(self.lbl)
        layout.addWidget(self.dialog)
        layout.addWidget(self.but)
        layout.addWidget(self.calculated)

        self.dialog.addItem("Regular")
        self.dialog.addItem("Euro Regular")
        self.dialog.addItem("Diesel")
        self.setGeometry(100,100,200,200)
        self.but.clicked.connect(self.calculate)
        self.setLayout(layout)
        self.show()
    def calculate(self, layout):
        if self.litre.text() == "":
            self.calculated.setText("<font color=red>Please Enter Litre")
        else:
            litre_int = int(self.litre.text())
            self.calculated.setText(litre_int*int(2.27))
类对话框(QDialog): 定义初始化(自): QDialog.\uuuuu init\uuuuuu(自) self.dialog=QComboBox() self.lbl=QLabel(“选择气体名称:”) self.but=QPushButton(“计算”) self.L=QLineEdit(self) self.regular=QLabel(“regular>>>”+str(2.27)) self.euro_reg=QLabel(“euro Regular>>>”+str(2.33)) self.diesel=QLabel(“diesel>>>”+str(2.39)) self.calculated=QLabel(“”) self.init_ui() def初始用户界面(自身): layout=QVBoxLayout() layout.addWidget(self.regular) layout.addWidget(self.euro_reg) layout.addWidget(self.diesel) layout.addWidget(自升) layout.addWidget(self.lbl) layout.addWidget(self.dialog) layout.addWidget(self.but) layout.addWidget(自计算) self.dialog.addItem(“常规”) self.dialog.addItem(“欧元常规”) self.dialog.addItem(“柴油机”) 自设置几何体(100100200200) self.but.clicked.connect(self.calculate) self.setLayout(布局) self.show() def计算(自我,布局): 如果self.litre.text()==“”: self.computed.setText(“请输入升”) 其他: 升\u int=int(self.lill.text()) 自计算的setText(升/升整数*整数(2.27))
setText
需要字符串,而不是int。您需要将结果显式转换为字符串:

self.calculated.setText(str(litre_int*int(2.27)))
# Here -----------------^

您应该转换最后一行中的参数以获得一个字符串:
self.calculated.setText(str(l_int*int(2.27)))