pyqt5在textBrowser添加文本並自動滑動到底


pyqt5在textBrowser添加文本並自動滑動到底

說明:

1、按下按鈕pushButton,把單行文本框lineEdit里的內容循環不斷的添加到多行文本展示框textBrowser。
2、必須要用線程做這件事,不然主程序會卡死。
3、必須添加sleep(),不然主程序會卡死。
4、用函數的閉包做這樣的事情,效果很好。

  

信號與槽的連接:

1 self.pushButton_2.clicked.connect(MainWindow.slot1)

 

 槽函數:

1     def slot1(self):
2         def _slot1(textBrowser,lineEdit):
3             while True:
4                 textBrowser.append(lineEdit.text())   #文本框逐條添加數據
5                 textBrowser.moveCursor(textBrowser.textCursor().End)  #文本框顯示到底部
6                 time.sleep(0.2)
7 
8         threading.Thread(target=_slot1,args=(self.textBrowser,self.lineEdit)).start()

 

得到結果:

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM