every blog every motto: You can do more than you think.
https://blog.csdn.net/weixin_39190382?type=blog
0. 前言
pyqt 界面 显示 控制台的输出
1. 正文
class Signal(QObject):
text_update = pyqtSignal(str)
def write(self, text):
self.text_update.emit(str(text))
# loop = QEventLoop()
# QTimer.singleShot(100, loop.quit)
# loop.exec_()
QApplication.processEvents()
class Mainworkwindow(QMainWindow, Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
# 实时显示输出, 将控制台的输出重定向到界面中
sys.stdout = Signal()
sys.stdout.text_update.connect(self.updatetext)
def updatetext(self, text):
"""
更新textBrowser
"""
cursor = self.textBrowser.textCursor()
cursor.movePosition(QTextCursor.End)
self.textBrowser.append(text)
self.textBrowser.setTextCursor(cursor)
self.textBrowser.ensureCursorVisible()
参考
[1] https://blog.csdn.net/ccj15010192778/article/details/102704301
[2] https://blog.csdn.net/ccj15010192778/article/details/102704301
[3] https://blog.csdn.net/venture5/article/details/121423286