I want to use a for loop to display numbers from 0 to 4 in a textbox in sequence. However, the output is displayed all at once after the loop finishes. I don’t know how to make it display in real-time.
I have tried searching on Google and testing QThread multiple times, but I couldn’t solve the problem.
GUI.py
class WorkerThread(QThread):
update_signal = Signal(str)
def run(self):
temp = test.guiTest()
self.update_signal.emit(temp)
time.sleep(0.2)
class MainWindow(QMainWindow,Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
def pb_test_click(self):
self.worker = WorkerThread()
self.worker.update_signal.connect(self.update_label)
self.start_thread()
self.testPrint()
def testPrint(self):
for i in range(5):
temp = str(i)
self.text_log.appendPlainText(temp)
time.sleep(0.2)
return temp
def start_thread(self):
if not self.worker.isRunning():
self.worker.start()
def update_label(self, message):
self.text_log.appendPlainText(message)
I want to use a for loop to display numbers from 0 to 4 in a textbox in sequence. However, the output is displayed all at once after the loop finishes. I don’t know how to make it display in real-time.