0

I have a code to create a GUI in python using PyQt5 library. In the GUI I have a label named status. Now I want that the text that this label status shows is the output in the main() function by using print().

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        self.status = QtWidgets.QLabel(self.frame)
        self.status.setGeometry(QtCore.QRect(10, 490, 521, 71))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.status.sizePolicy().hasHeightForWidth())
        self.status.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(16)
        font.setItalic(True)
        self.status.setFont(font)
        self.status.setStyleSheet("background-color: rgb(254, 200, 30);\n"
"border: rgb(255,255,255);\n"
"border-thick:10px;\n"
"border-radius: 10px;\n"
"")
        self.status.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
        self.status.setObjectName("status")

if __name__ == "__main__":
    print("Getting ready...Please Wait !!")
    Add = True
    Remove = False
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    print("Ready")
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

Now, What I want is that both the print statements in the main block are visible in the status label one after the other. How can I do that?

I tried the solution mentioned in Print out Python console output to Qtextedit but this didn't solve my issue.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
ProgramHub
  • 21
  • 2
  • Does it show you've tried them? That you do not know how to apply it does not imply that it is not the solution. – eyllanesc Oct 28 '21 at 16:20
  • Yes, I applied the code mentioned in the link, in the link the widget is QTextEdit. In my case it is QLabel. Maybe that is the issue here. But I tried that code and it didn't work. If I have not pasted that code here, doesn't mean I don't know how to apply. – ProgramHub Oct 29 '21 at 16:24

0 Answers0