1
PyQt5를 사용하여 계산기 봇을 만들고 싶습니다.이 오류가 발생합니다. U 도와 드릴까요 ??PyQt5를 사용하여 계산기 봇을 만들고 싶습니다. 오류가 발생합니다.
P.S 내가 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))
: 당신은 명시 적으로 문자열로 결과를 변환해야 – PRMoureu