I want to direct console to Pyqt GUI
And I Search stackoverflow, find a answer
Print out python console output to Qtextedit
the code show below
class Stream(QtCore.QObject):
newText = QtCore.pyqtSignal(str)
def write(self, text):
self.newText.emit(str(text))
class Window(QtGui.QMainWindow):
def __init__(self):
super(Window, self).__init__()
self.setGeometry(50, 50, 500, 300)
self.setWindowTitle("PyQT tuts!")
self.setWindowIcon(QtGui.QIcon('pythonlogo.png'))
self.home()
sys.stdout = Stream(newText=self.onUpdateText)
def onUpdateText(self, text):
cursor = self.process.textCursor()
cursor.movePosition(QtGui.QTextCursor.End)
cursor.insertText(text)
self.process.setTextCursor(cursor)
self.process.ensureCursorVisible()
def __del__(self):
sys.stdout = sys.__stdout__
i have two questions.
why
def write(self, text)
is defined but not useWhat does the parameter in
Stream(newText=self.onUpdateText)
mean, and my pycharm give me a warn Unexpected argument