2017-12-31 38 views
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)) 
+2

:あなたは、明示的に結果を文字列に変換する必要があります – PRMoureu

答えて

1

setTextは、文字列ではなく、int型を期待しています。 `` self.calculated.setText(STR(litre_intの*はint(2.27))):あなたは、文字列を取得するために、最後の行にパラメータを変換する必要があり

self.calculated.setText(str(litre_int*int(2.27))) 
# Here -----------------^ 
関連する問題