0

I was making an application in PyQt5 and needed to update a label continuously. Here is my code:

count = 0

def update():
    global count
    count += 1
    theLabel.setText(str(count))

while True:
    threading.Thread(target=update).start()

But, what ends up happening is that the window simply crashes without updating the label at all. I was wondering if there is a better way to do this without crashing the window. TIA

Mysterious K
  • 79
  • 2
  • 8
  • 1
    Why are you creating infinitely many threads? You need only one thread and move the inifnite loop to the function that is the target of your thread. Also, you shouldn't really update widgets from threads that are not the main thread. Use signals and slots instead. – Heike Dec 04 '20 at 13:39
  • @Heike I need many threads running at the same time instead of just one, and, I would appreciate it if you could link me to some docs for signals and slots. – Mysterious K Dec 04 '20 at 13:46

0 Answers0