0

I am trying to either have a table cell or label display the looped result but am dealing with freezing.

def counter(self):
        while True:
            for number in range(10000): 
                print(str(number))
                time.sleep(2)

Works perfectly. But if I change it to below:

def counter(self):
        while True:
            for number in range(10000): 
                label1.settext(str(number))
                time.sleep(2)

It freezes the gui and no matter how much sleep I put it will not display the results. Using Pyqt5 for the label and/or table. Print works perfect but when I tell it to display it freezes and shows blank.

MasterCode
  • 25
  • 6
  • Possibly a bug in qt: https://forum.qt.io/topic/98059/push-button-label-settext-not-refreshing-under-macos – Ghoti Aug 10 '21 at 14:59
  • You simply shouldn't use an infinite loop or sleep in the GUI thread. You are essentially blocking the GUI from updating. Unless you tell us what exactly you are trying to achieve we can't help you. – Art Aug 10 '21 at 15:01
  • @Art I used this as a test, basically I have a serial cable receiving a simple engine speed signal. So when I insert the "while true" loop on the output using the "print method", it prints perfectly all of the receiving signal of the serial cable, but when I try to display it, it freezes. I would like to just display the information received in a textbox or table cell without freezing. – MasterCode Aug 10 '21 at 15:14
  • Have you looked at [threading in pyqt](https://stackoverflow.com/questions/6783194/background-thread-with-qthread-in-pyqt)? Also, if you need to display in table cell you don't need a label, you can use [QTableWidget](https://doc.qt.io/qt-5/qtablewidget.html) – Art Aug 10 '21 at 15:19
  • @Art in regards to the label, I was just stating it can be displayed in either, I was just having no luck due to freezing. I have even put the looping in a loop.py and called it in the main.py, same issue. Odd it works flawless on print. – MasterCode Aug 10 '21 at 15:27

0 Answers0