目的:將程序的輸出內容在TextBrowser中顯示
實現:
假定定義的TextBrowser名爲textBrowser,主界面名爲Ui_MainWindow。直接定義一個textBrowser的輸出函數:
def printf(self, mes):
self.textBrowser.append(mes) # 在指定的區域顯示提示信息
self.cursot = self.textBrowser.textCursor()
self.textBrowser.moveCursor(self.cursot.End)
想要在TextBrowse中顯示輸出時,直接調用printf即可:
Ui_MainWindow.printf(self, "程序輸出內容")