Как обратиться к числу написанному внутри LineEdit?

Я работаю в Pyside Мне нужно чтобы я смог как либо обратиться к числу или тексту написанному внутри программного окошка в LineEdit, допустим мне хочется чтобы после нажатия кнопки к тому числу которое я написал прибавилась двойка. как мне это сделать? Код:

import PySide
import self as self
from PySide import QtCore, QtGui
import sys
from ui3 import Ui_Dialog
class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(400, 391)
        Dialog.setCursor(QtCore.Qt.ArrowCursor)
        Dialog.setStyleSheet("QDialog{\n"
"background:#434542;\n"
"}")
        self.pushButton = QtGui.QPushButton(Dialog)
        self.pushButton.setGeometry(QtCore.QRect(330, 20, 51, 51))
        font = QtGui.QFont()
        font.setFamily("Century Gothic")
        font.setPointSize(16)
        font.setWeight(75)
        font.setBold(True)
        self.pushButton.setFont(font)
        self.pushButton.setCursor(QtCore.Qt.ArrowCursor)
        self.pushButton.setStyleSheet("QPushButton {\n"
"background: #282928;\n"
" border: 3px solid #FFFFFF;\n"
" border-radius: 10px;\n"
"border-color: #7ad442;\n"
"color:#ffffff;\n"
"\n"
"}\n"
"")
        self.pushButton.setObjectName("pushButton")
        self.textBrowser = QtGui.QTextBrowser(Dialog)
        self.textBrowser.setGeometry(QtCore.QRect(20, 190, 281, 131))
        font = QtGui.QFont()
        font.setFamily("Century Gothic")
        self.textBrowser.setFont(font)
        self.textBrowser.setStyleSheet("QTextBrowser {\n"
"background: #434542;\n"
"border: 3px solid #7ad442;\n"
"\n"
"}")
        self.textBrowser.setObjectName("textBrowser")
        self.label_2 = QtGui.QLabel(Dialog)
        self.label_2.setGeometry(QtCore.QRect(10, 340, 281, 41))
        font = QtGui.QFont()
        font.setFamily("Univers Condensed")
        font.setPointSize(11)
        font.setWeight(75)
        font.setBold(True)
        self.label_2.setFont(font)
        self.label_2.setStyleSheet("QLabel {\n"
"background:#282928;\n"
"border: 3px solid #FFFFFF;\n"
" border-radius: 10px;\n"
"border-color: #7ad442;\n"
"color:#ffffff;\n"
"}")
        self.label_2.setObjectName("label_2")
        self.textEdit = QtGui.QTextEdit(Dialog)
        self.textEdit.setGeometry(QtCore.QRect(30, 20, 281, 41))
        font = QtGui.QFont()
        font.setPointSize(14)
        font.setWeight(75)
        font.setBold(True)
        self.textEdit.setFont(font)
        self.textEdit.setStyleSheet("QTextEdit {\n"
"\n"
" background: #282928;\n"
" border: 3px solid #FFFFFF;\n"
" border-radius: 20px;\n"
"border-color: #7ad442;\n"
" color:#ffffff;\n"
"}\n"
"QTextEdit: hover {\n"
"backgroung:#ffffff\n"
"}")
        self.textEdit.setObjectName("textEdit")
        self.lineEdit = QtGui.QLineEdit(Dialog)
        self.lineEdit.setGeometry(QtCore.QRect(30, 80, 281, 41))
        self.lineEdit.setStyleSheet("QLineEdit {\n"
"\n"
" background: #282928;\n"
" border: 3px solid #FFFFFF;\n"
" border-radius: 10px;\n"
"border-color: #7ad442;\n"
" color:#ffffff;\n"
"}\n"
"QTextEdit: hover {\n"
"backgroung:#ffffff\n"
"}")
        self.lineEdit.setObjectName("lineEdit")

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton.setText(QtGui.QApplication.translate("Dialog", "OK", None, QtGui.QApplication.UnicodeUTF8))
        self.textBrowser.setHtml(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Century Gothic\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы </span></p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы</span></p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы</span></p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы</span></p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.label_2.setText(QtGui.QApplication.translate("Dialog", "ИМТ - Индекс массы тела", None, QtGui.QApplication.UnicodeUTF8))
        self.textEdit.setHtml(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; font-weight:600; font-style:normal;\">\n"
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))


#
app = QtGui.QApplication(sys.argv)
#
Dialog = QtGui.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
#Действие

#
sys.exit(app.exec_())

Нужно написать логический код в: #Действие


Ответы (3 шт):

Автор решения: gil9red

мне хочется чтобы после нажатия кнопки к тому числу которое я написал прибавилась двойка

Для этого нужно повесить сигнал кнопки clicked на метод, а в методе обратиться к текущему тексту lineEdit и поменять его:

self.ui.pushButton.clicked.connect(self._on_push_button_click)
...

    def _on_push_button_click(self):
        value = self.ui.lineEdit.text()
        self.ui.lineEdit.setText(value + "2")

Сделал отдельный класс, в которым добавил элементы из Ui_Dialog. Советую и вам так дальше делать, т.к. лучше разделять графический интерфейс и логику под сущностям.

Пример:

from PySide import QtCore, QtGui
import sys

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(400, 391)
        Dialog.setCursor(QtCore.Qt.ArrowCursor)
        Dialog.setStyleSheet("QDialog{\n"
"background:#434542;\n"
"}")
        self.pushButton = QtGui.QPushButton(Dialog)
        self.pushButton.setGeometry(QtCore.QRect(330, 20, 51, 51))
        font = QtGui.QFont()
        font.setFamily("Century Gothic")
        font.setPointSize(16)
        font.setWeight(75)
        font.setBold(True)
        self.pushButton.setFont(font)
        self.pushButton.setCursor(QtCore.Qt.ArrowCursor)
        self.pushButton.setStyleSheet("QPushButton {\n"
"background: #282928;\n"
" border: 3px solid #FFFFFF;\n"
" border-radius: 10px;\n"
"border-color: #7ad442;\n"
"color:#ffffff;\n"
"\n"
"}\n"
"")
        self.pushButton.setObjectName("pushButton")
        self.textBrowser = QtGui.QTextBrowser(Dialog)
        self.textBrowser.setGeometry(QtCore.QRect(20, 190, 281, 131))
        font = QtGui.QFont()
        font.setFamily("Century Gothic")
        self.textBrowser.setFont(font)
        self.textBrowser.setStyleSheet("QTextBrowser {\n"
"background: #434542;\n"
"border: 3px solid #7ad442;\n"
"\n"
"}")
        self.textBrowser.setObjectName("textBrowser")
        self.label_2 = QtGui.QLabel(Dialog)
        self.label_2.setGeometry(QtCore.QRect(10, 340, 281, 41))
        font = QtGui.QFont()
        font.setFamily("Univers Condensed")
        font.setPointSize(11)
        font.setWeight(75)
        font.setBold(True)
        self.label_2.setFont(font)
        self.label_2.setStyleSheet("QLabel {\n"
"background:#282928;\n"
"border: 3px solid #FFFFFF;\n"
" border-radius: 10px;\n"
"border-color: #7ad442;\n"
"color:#ffffff;\n"
"}")
        self.label_2.setObjectName("label_2")
        self.textEdit = QtGui.QTextEdit(Dialog)
        self.textEdit.setGeometry(QtCore.QRect(30, 20, 281, 41))
        font = QtGui.QFont()
        font.setPointSize(14)
        font.setWeight(75)
        font.setBold(True)
        self.textEdit.setFont(font)
        self.textEdit.setStyleSheet("QTextEdit {\n"
"\n"
" background: #282928;\n"
" border: 3px solid #FFFFFF;\n"
" border-radius: 20px;\n"
"border-color: #7ad442;\n"
" color:#ffffff;\n"
"}\n"
"QTextEdit: hover {\n"
"backgroung:#ffffff\n"
"}")
        self.textEdit.setObjectName("textEdit")
        self.lineEdit = QtGui.QLineEdit(Dialog)
        self.lineEdit.setGeometry(QtCore.QRect(30, 80, 281, 41))
        self.lineEdit.setStyleSheet("QLineEdit {\n"
"\n"
" background: #282928;\n"
" border: 3px solid #FFFFFF;\n"
" border-radius: 10px;\n"
"border-color: #7ad442;\n"
" color:#ffffff;\n"
"}\n"
"QTextEdit: hover {\n"
"backgroung:#ffffff\n"
"}")
        self.lineEdit.setObjectName("lineEdit")

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton.setText(QtGui.QApplication.translate("Dialog", "OK", None, QtGui.QApplication.UnicodeUTF8))
        self.textBrowser.setHtml(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Century Gothic\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы </span></p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы</span></p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы</span></p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы</span></p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.label_2.setText(QtGui.QApplication.translate("Dialog", "ИМТ - Индекс массы тела", None, QtGui.QApplication.UnicodeUTF8))
        self.textEdit.setHtml(QtGui.QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; font-weight:600; font-style:normal;\">\n"
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))


class MainWindow(QtGui.QDialog):
    def __init__(self):
        super().__init__()

        self.ui = Ui_Dialog()
        self.ui.setupUi(self)

        self.ui.pushButton.clicked.connect(self._on_push_button_click)

    def _on_push_button_click(self):
        value = self.ui.lineEdit.text()
        self.ui.lineEdit.setText(value + "2")


if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)

    mw = MainWindow()
    mw.show()

    sys.exit(app.exec_())

PS.

Советую давать виджетам на форме в objectName свои названия, чтобы при генерации кода по форме, они получали понятные названия.

Например, для кнопки pushButton с objectName=pushButton можно было дать, например, такое название objectName = pb_ok, тогда в коде будет понятнее для чего этот виджет

→ Ссылка
Автор решения: S. Nick

Рекомендую повысить версию до PySide2 или PyQt5 и можно попробовать:

'''
import PySide
import self as self
from PySide import QtCore, QtGui
'''
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.Qt import *


#from ui3 import Ui_Dialog
class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(400, 391)
        Dialog.setCursor(QtCore.Qt.ArrowCursor)
        Dialog.setStyleSheet("QDialog{\n"
"background:#434542;\n"
"}")
        self.pushButton = QPushButton(Dialog)
        self.pushButton.setGeometry(QtCore.QRect(330, 20, 51, 51))
        font = QtGui.QFont()
        font.setFamily("Century Gothic")
        font.setPointSize(16)
        font.setWeight(75)
        font.setBold(True)
        self.pushButton.setFont(font)
        self.pushButton.setCursor(QtCore.Qt.ArrowCursor)
        self.pushButton.setStyleSheet("QPushButton {\n"
"background: #282928;\n"
" border: 3px solid #FFFFFF;\n"
" border-radius: 10px;\n"
"border-color: #7ad442;\n"
"color:#ffffff;\n"
"\n"
"}\n"
"")
        self.pushButton.setObjectName("pushButton")
        self.textBrowser = QTextBrowser(Dialog)
        self.textBrowser.setGeometry(QtCore.QRect(20, 190, 281, 131))
        font = QtGui.QFont()
        font.setFamily("Century Gothic")
        self.textBrowser.setFont(font)
        self.textBrowser.setStyleSheet("QTextBrowser {\n"
"background: #434542;\n"
"border: 3px solid #7ad442;\n"
"\n"
"}")
        self.textBrowser.setObjectName("textBrowser")
        self.label_2 = QLabel(Dialog)
        self.label_2.setGeometry(QtCore.QRect(10, 340, 281, 41))
        font = QtGui.QFont()
        font.setFamily("Univers Condensed")
        font.setPointSize(11)
        font.setWeight(75)
        font.setBold(True)
        self.label_2.setFont(font)
        self.label_2.setStyleSheet("QLabel {\n"
"background:#282928;\n"
"border: 3px solid #FFFFFF;\n"
" border-radius: 10px;\n"
"border-color: #7ad442;\n"
"color:#ffffff;\n"
"}")
        self.label_2.setObjectName("label_2")
        self.textEdit = QTextEdit(Dialog)
        self.textEdit.setGeometry(QtCore.QRect(30, 20, 281, 41))
        font = QtGui.QFont()
        font.setPointSize(14)
        font.setWeight(75)
        font.setBold(True)
        self.textEdit.setFont(font)
        self.textEdit.setStyleSheet("QTextEdit {\n"
"\n"
" background: #282928;\n"
" border: 3px solid #FFFFFF;\n"
" border-radius: 20px;\n"
"border-color: #7ad442;\n"
" color:#ffffff;\n"
"}\n"
"QTextEdit: hover {\n"
"backgroung:#ffffff\n"
"}")
        self.textEdit.setObjectName("textEdit")
        self.lineEdit = QLineEdit(Dialog)
        self.lineEdit.setGeometry(QtCore.QRect(30, 80, 281, 41))
        self.lineEdit.setStyleSheet("QLineEdit {\n"
"\n"
" background: #282928;\n"
" border: 3px solid #FFFFFF;\n"
" border-radius: 10px;\n"
"border-color: #7ad442;\n"
" color:#ffffff;\n"
"}\n"
"QTextEdit: hover {\n"
"backgroung:#ffffff\n"
"}")
        self.lineEdit.setObjectName("lineEdit")

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        '''
        Dialog.setWindowTitle(QApplication.translate("Dialog", "Dialog", None, QApplication.UnicodeUTF8))
        self.pushButton.setText(QApplication.translate("Dialog", "OK", None, QApplication.UnicodeUTF8))
        self.textBrowser.setHtml(QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Century Gothic\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы </span></p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы</span></p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы</span></p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы</span></p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        self.label_2.setText(QApplication.translate("Dialog", "ИМТ - Индекс массы тела", None, QApplication.UnicodeUTF8))
        self.textEdit.setHtml(QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; font-weight:600; font-style:normal;\">\n"
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
        '''
        Dialog.setWindowTitle(QApplication.translate("Dialog", "Dialog"))
        self.pushButton.setText(QApplication.translate("Dialog", "OK"))
        self.textBrowser.setHtml(QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Century Gothic\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы </span></p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы</span></p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы</span></p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы</span></p>\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы</span></p></body></html>"))
        self.label_2.setText(QApplication.translate("Dialog", "ИМТ - Индекс массы тела"))
        self.textEdit.setHtml(QApplication.translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; font-weight:600; font-style:normal;\">\n"
"<p style=\"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><br /></p></body></html>"))


class MainWindow(QDialog, Ui_Dialog):
    def __init__(self):
        super().__init__()
        
        self.setupUi(self)
        self.pushButton.clicked.connect(self.onClickedOk)
        
    def onClickedOk(self):
        num = self.lineEdit.text()
        if num.isdigit():
#            print(int(num))
            rez = str(int(num)+2)
            print(rez)
            # так
            #self.textEdit.setText(f'{num} + 2 = {rez}')
            # или так
            self.textEdit.setText(num + ' + 2 = ' + rez)


#
app = QApplication(sys.argv)
#
Dialog = MainWindow() #QDialog()
#ui = Ui_Dialog()
#ui.setupUi(Dialog)
Dialog.show()
#Действие

#
sys.exit(app.exec_())

введите сюда описание изображения

→ Ссылка
Автор решения: JluMoH4uk

Всем спасибо кто помогал мне решить данную проблему. Отдельно выражаю благодарность @S.Nick! Мой вопрос решён. В итоге получился вот такой код:


from PySide import QtCore, QtGui
import sys

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(400, 391)
        Dialog.setCursor(QtCore.Qt.ArrowCursor)
        Dialog.setStyleSheet("QDialog{\n"
                             "background:#434542;\n"
                             "}")
        self.pushButton = QtGui.QPushButton(Dialog)
        self.pushButton.setGeometry(QtCore.QRect(330, 20, 51, 51))
        font = QtGui.QFont()
        font.setFamily("Century Gothic")
        font.setPointSize(16)
        font.setWeight(75)
        font.setBold(True)
        self.pushButton.setFont(font)
        self.pushButton.setCursor(QtCore.Qt.ArrowCursor)
        self.pushButton.setStyleSheet("QPushButton {\n"
                                      "background: #282928;\n"
                                      " border: 3px solid #FFFFFF;\n"
                                      " border-radius: 10px;\n"
                                      "border-color: #7ad442;\n"
                                      "color:#ffffff;\n"
                                      "\n"
                                      "}\n"
                                      "")
        self.pushButton.setObjectName("pushButton")
        self.textBrowser = QtGui.QTextBrowser(Dialog)
        self.textBrowser.setGeometry(QtCore.QRect(20, 190, 281, 131))
        font = QtGui.QFont()
        font.setFamily("Century Gothic")
        self.textBrowser.setFont(font)
        self.textBrowser.setStyleSheet("QTextBrowser {\n"
                                       "background: #434542;\n"
                                       "border: 3px solid #7ad442;\n"
                                       "\n"
                                       "}")
        self.textBrowser.setObjectName("textBrowser")
        self.label_2 = QtGui.QLabel(Dialog)
        self.label_2.setGeometry(QtCore.QRect(10, 340, 281, 41))
        font = QtGui.QFont()
        font.setFamily("Univers Condensed")
        font.setPointSize(11)
        font.setWeight(75)
        font.setBold(True)
        self.label_2.setFont(font)
        self.label_2.setStyleSheet("QLabel {\n"
                                   "background:#282928;\n"
                                   "border: 3px solid #FFFFFF;\n"
                                   " border-radius: 10px;\n"
                                   "border-color: #7ad442;\n"
                                   "color:#ffffff;\n"
                                   "}")
        self.label_2.setObjectName("label_2")
        self.lineEdit = QtGui.QLineEdit(Dialog)
        self.lineEdit.setGeometry(QtCore.QRect(30, 80, 281, 41))
        self.lineEdit.setStyleSheet("QLineEdit {\n"
                                    "\n"
                                    " background: #282928;\n"
                                    " border: 3px solid #FFFFFF;\n"
                                    " border-radius: 10px;\n"
                                    "border-color: #7ad442;\n"
                                    " color:#ffffff;\n"
                                    "}\n"
                                    "QTextEdit: hover {\n"
                                    "backgroung:#ffffff\n"
                                    "}")
        self.lineEdit.setObjectName("lineEdit")
        self.lineEdit_2 = QtGui.QLineEdit(Dialog)
        self.lineEdit_2.setGeometry(QtCore.QRect(30, 20, 281, 41))
        self.lineEdit_2.setStyleSheet("QLineEdit {\n"
                                      "\n"
                                      " background: #282928;\n"
                                      " border: 3px solid #FFFFFF;\n"
                                      " border-radius: 10px;\n"
                                      "border-color: #7ad442;\n"
                                      " color:#ffffff;\n"
                                      "}\n"
                                      "QTextEdit: hover {\n"
                                      "backgroung:#ffffff\n"
                                      "}")
        self.lineEdit_2.setObjectName("lineEdit_2")

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton.setText(QtGui.QApplication.translate("Dialog", "OK", None, QtGui.QApplication.UnicodeUTF8))
        self.textBrowser.setHtml(QtGui.QApplication.translate("Dialog",
                                                              "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
                                                              "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
                                                              "p, li { white-space: pre-wrap; }\n"
                                                              "</style></head><body style=\" font-family:\'Century Gothic\'; font-size:8.25pt; font-weight:400; font-style:normal;\">\n"
                                                              "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы </span></p>\n"
                                                              "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы</span></p>\n"
                                                              "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы</span></p>\n"
                                                              "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы</span></p>\n"
                                                              "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-family:\'MS Shell Dlg 2\'; font-size:14pt; color:#39ff6a;\">ИМТ      &gt;18       ниже нормы</span></p></body></html>",
                                                              None, QtGui.QApplication.UnicodeUTF8))
        self.label_2.setText(
            QtGui.QApplication.translate("Dialog", "ИМТ - Индекс массы тела", None, QtGui.QApplication.UnicodeUTF8))


class MainWindow(QtGui.QDialog):
    def __init__(self):
        super().__init__()

        self.ui = Ui_Dialog()
        self.ui.setupUi(self)

        self.ui.pushButton.clicked.connect(self._on_push_button_click)

    def _on_push_button_click(self):
        value = self.ui.lineEdit_2.text()
        rez = str(int(value)+2)
        self.ui.lineEdit.setText(rez)


if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)

    mw = MainWindow()
    mw.show()

    sys.exit(app.exec_())

Программа

→ Ссылка