current position:Home>On the display of textbroswer loop in pyqt5

On the display of textbroswer loop in pyqt5

2022-01-27 01:06:57 CSDN Q & A

The phenomenon and background of the problem

I use pyqt5 Medium textBrowser Cyclic display of numbers , In order to solve the thread jam problem , I created a new thread , Every time 3 Send a signal once a second . What I want to achieve is , In a cycle ,textBrowser Yes 1 Second time is blank ,2 Second time is the time to display numbers , But the result is 3 Seconds are showing numbers .

This is the slot function for text display
    def shownum2(self):        self.Simple.textBrowser_right.clear()        time.sleep(1)        self.Simple.textBrowser_right.setText(" " + str(self.workThread2.num2))

This is the signal

class workThread2(QThread):    #  Define signals through class member objects     tb_right = pyqtSignal(str)    def run(self):        while True:            self.num2 = random.choice(range(10))            print("num2_create", self.num2, time.ctime())            self.tb_right.emit(str(self.num2))            time.sleep(3)

How can I get to TextBroswer in 1 Second blank ,2 The effect of displaying numbers in seconds ?
Thank you for




Refer to the answer 1:

Loop start , Clear the previously displayed numbers , Refresh the interface , wait for 1s, Load the displayed number , Refresh the interface , wait for 2s, Then what do you need in the back




Refer to the answer 2:



Refer to the answer 3:

Refresh when it becomes blank , That's the problem




Refer to the answer 4:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270106554457.html

Random recommended