PyQt how to capture print output and display in text field
<p>The following script is part of a more complex one. I have taken out some parts just for simplification. </p>

<p>My aim is to insert a textedit field that captures the print output of the command window (when the pushbutton is pressed) and displays it inside the text field while the program is executing. </p>

<p>The suggestions I found are too much aimed at scripts that have no other functions. But my script is already quite complex and I don’t want to change it from the beginning or rewrite the whole script.
Does anyone have an idea on how to include the function in the script in a relatively simple way? I have tried it without success. </p>

<p>Any kind help would be appreciated.  </p>

<pre><code>import sys
import subprocess
from PyQt4 import QtCore, QtGui

class MainWindow(QtGui.QMainWindow):

    def __init__(self, parent=None):

        super(MainWindow, self).__init__(parent)

        self.win_widget = WinWidget(self)
        widget = QtGui.QWidget()
        layout = QtGui.QVBoxLayout(widget)
        layout.addWidget(self.win_widget)
        self.setCentralWidget(widget)

        self.statusBar().showMessage('Ready')

        self.setGeometry(300, 300, 450, 250)
        self.setWindowTitle('capture PyQt output')  
        self.setWindowIcon (QtGui.QIcon('logo.png'))
        self.show()


class WinWidget (QtGui.QWidget) : 


    def __init__(self, parent): 

        super (WinWidget , self).__init__(parent)
        self.controls()
        self.grid_layout() 
        self.capture_output()


    def controls(self):

        self.btn_newSearch = QtGui.QPushButton('capture PyQt output', self)  
        self.btn_newSearch.clicked.connect(self.some_funtion)
        self.btn_newSearch.setFont(QtGui.QFont('CourierNew', 12 , QtGui.QFont.Bold,False))



    def capture_output (self) :

        # HERE I WANT TO PUT A (IF POSSIBLE SIMPLE) SCRIPT TO CAPTURE 
    COOMAND WINDOW OUTPUT
        something like:
        self.text_box = QtGui.QPlainTextEdit()
        text= capured output
        self.text_box.setPlainText(text)


    def grid_layout (self) : 
        grid = QtGui.QGridLayout()
        grid.setSpacing(2)
        grid.addWidget(self.btn_newSearch , 1 , 1)
        grid.addWidget(self.text_box , 2 , 1)
        self.setLayout(grid)

    def some_funtion (self) :
        print "hello world"

def main():

    app = QtGui.QApplication(sys.argv)
    win = MainWindow()
    win.show()
   sys.exit(app.exec_())


if __name__ == '__main__':
    main()
</code></pre>