1
私はPyQt5を使って電卓ボットを作ってみたいと思います。 Uは私を助けることができますか?私はPyQt5私はPyQt5を使って電卓ボットを作りたいと思っています。私はエラーが発生しています。
にBegginer午前
P.Sは私のエラーはこれです:
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))
:あなたは、明示的に結果を文字列に変換する必要があります – PRMoureu