pyqt5 | how to make text display in QPlainTextEdit

Question:

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)
Asked By: lobzinc

||

Answers:

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.

Answered By: lobzinc
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.