看板 Python 關於我們 聯絡資訊
因為想學習使用Qthread方式來避免pyqt的畫面會凍結的問題。 以下是我的程式碼 class MyWidget(QWidget): def __init__(self, parent = None): super(MyWidget, self).__init__(parent) ... def createLayout(self): self.button_config= QPushButton(self) combo_box_option = ["1","3","5","10","20"] self.combo = QComboBox(self) for t in combo_box_option: self.combo.addItem(t) ... ... thread = MyThread() thread.changed_signal.connect(self.update) self.button_config.clicked.connect(lambda :thread.start()) def update(self): config_result = int(self.combo_box_option.currentText()) class MyThread(QThread): changed_signal = pyqtSignal(int) def __init__(self,parent=None): super(MyThread,self).__init__(parent) def run(self): for i in range(x): self.sec_changed_signal.emit(i) time.sleep(1) 想知道有沒有辦法讓最後一個for迴圈裡面的x值, 能夠等於前一個class裡面最後一行下拉式選擇後的config_result 或是有其他種寫法可以達成在使用迴圈時,GUI不會出現無法反應的狀態。 謝謝各位~ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.250.186.18 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1512563956.A.06C.html