看板 Python 關於我們 聯絡資訊
PyQT5 基本功能大致上會用,但目前有一個不解的地方,想請問大家。 程式的流程如下: 1.在GUI 輸出"Running" 字樣 2.call sub functon. 這個會花三到五分鐘的時間。 3.在GUI 輸出"finish" 字樣 但很奇怪的是,1就不會輸出,只會看到3的結果。 code 節錄如下: def pushbutton(self): self.textBrowser.setText("running") #1 subfunction() #2 self.textBrowser.setText("finish") #3 我那邊理解有錯嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.160.117.94 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1579709612.A.077.html
brt: main thread 被 subfunction 帶走 沒來得及更新畫面 然後結束01/23 00:55
brt: 你不能在 event loop 裡面進行計算 這會 block event loop01/23 00:56
大概懂你的意思。 但我想要執行subfuncation的時候,秀running.有建議的做法嗎? 感謝您的回應。 ※ 編輯: a9202507 (118.160.117.94 臺灣), 01/23/2020 11:56:09
brt: 另外發起一個 Thread 然後利用 Qt Signal/Slot 機制觸發01/23 13:18
brt: ref: https://tinyurl.com/vmabpfs01/23 13:42
感謝。昨天用thread功能後,問題解了。 ※ 編輯: a9202507 (180.217.149.176 臺灣), 01/24/2020 11:02:30