Search code examples
qtpython-3.4qt-designer

Print inside widget


Windows 7, In Python 3.4 I created a very simple program that just prints "Something". And made a very simple gui in QT Designer for it with 1 button "Print it". Converted .ui file to .py file, made some adjustments.

Everything works, BUT for printing it opens console and prints "Something" there. I want this "Something" to be printed INSIDE my widget. And If any mistakes in program - I want them also to be printed INSIDE my widget.

What element of QT Designer should I use? An element which takes all printing from program and prints it inside itself. Or maybe I should use something else but function "Print()"?

Thank you very much.


Solution

  • Probably want either a QLabel (setText method) or if there is a bunch of text to print a QTextEdit (append method).

    import sys
    
    app = QtGui.QApplication([])
    
    widget = QtGui.QLabel("My Label")
    widget.setText("New Value")
    widget.show()
    
    sys.exit(app.exec_())