在主界面Ui_MainWindow类中自定义一个printf函数,如下:
def printf(self, mes):
self.textBrowser.append(mes) # 在指定的区域显示提示信息
self.cursot = self.textBrowser.textCursor()
self.textBrowser.moveCursor(self.cursot.End)
QtWidgets.QApplication.processEvents()
其中最后一行必须加上才能实现信息一行一行实时输出,否则信息会在程序执行结束后才一起输出。
在主程序中,需要输出信息的地方调用这个printf函数即可实现:
Ui_MainWindow.printf(self,'aaaa')