lobzinc
lobzinc

Reputation: 23

pyqt5 | how to make text display in QPlainTextEdit

I want two numbers to be entered and one divided by the other and at the end the quotient is output to QPlainTextEdit, but I can' t do it right. here is a problematic piece of code

def electrovolnyshablon():
    global ElectroVolSh
    ElectroVolSh = QtWidgets.QMainWindow()
    uie = ElectroVolni()
    uie.ShablonElectro(ElectroVolSh)
    ElectroVolSh.show()
    MainElectric.hide()
    uie.lineEdit_2.setPlaceholderText('Указывайте в метрах (м)')
    uie.lineEdit.setPlaceholderText("Указывайте в м/c")

    def nazadlzadacham():
        MainElectric.show()
        ElectroVolSh.hide()

    #############specifically here########################
    def obrabotka(): 
        dlinavolni = int(uie.lineEdit_2.text())
        skorc = int(uie.lineEdit.text())
        otvett = dlinavolni / skorc
        #if not skorc:
        #    otvett = dlinavolni / 300000000
        #else:
        #    skorc1 = int(skorc)
        #    otvett = dlinavolni / skorc1

        uie.plainTextEdit.setText(str(otvett))

    uie.pushButton.clicked.connect(obrabotka)
    uie.pushButton_3.clicked.connect(nazadlzadacham)

Upvotes: 0

Views: 322

Answers (1)

lobzinc
lobzinc

Reputation: 23

First, the text should be output via setPlainText, that is, it should look like this: uie.plainTextEdit.setPlainText(str(otvett))

Secondly, you need to convert to int after checking for an empty input.

Upvotes: 1

Related Questions