K
K
Kir Mozor2022-03-06 22:25:03
Python
Kir Mozor, 2022-03-06 22:25:03

Qt Python program hangs due to time.sleep(), how to fix?

Hello everyone, I am writing a client for Yandex Music on Unix using PyQt
I don’t have much experience with PyQt, and I don’t have experience with threads
So that’s the question, my program should pause at a certain moment, for this I use time.sleep()

class ExampleApp(QtWidgets.QMainWindow, design.Ui_MainWindow):
        def __init__(self):
                # Это здесь нужно для доступа к переменным, методам
                # и т.д. в файле design.py
                super().__init__()
                self.setupUi(self)  # Это нужно для инициализации нашего дизайна
                print(1+1)
                time.sleep(40) # И тут зависает намертво Qt до 40 секунд

I know where the error is, I know what the error is, but due to the fact that I have little experience with PyQt, I don’t know how to fix it
Please help)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HemulGM, 2022-03-07
@150_Kirill_150

Because you yourself set sleep. Any GUI program runs on the main thread, and you stop it for 40 seconds. Because of the stop, window messages are not processed, and this is the basis of the application's work with the GUI.

PS
Не перестаю поражаться тому, как люди "пишут" программы не понимая что делают

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question