J
J
jerwright2021-08-12 10:41:02
Python
jerwright, 2021-08-12 10:41:02

How to remove lags in PySide2?

Good day. I encountered such a problem that during the execution of the cycle by a program written in PySide2, the window itself starts to freeze, unlike the console. Maybe it's time.sleep, but I tried it with QThread.sleep as well.

The code:

def fishing():

    sct = mss.mss()

    timeout = checking_timer()
    adding_box(msg_titles[0], f"Начало через {timeout} с. Скорее забросьте удочку! И обязательно откройте игру в оконном режиме для полноценной работы программы.", warning=None)
    ui.timeout_label.show()
    ui.timeout_info.show()
    while int(timeout)!=0:
        print(timeout)
        ui.timeout_info.setText(f'{timeout} секунд')
        timeout -= 1
        time.sleep(1)


    #ui.timeout_info.setText(f'{timeout} секунд')
    #timeout -= 1
    #time.sleep(1)
    
        
    ui.timeout_label.setText("Программа")
    ui.timeout_info.setText("запустилась!")
 
    click()
    #print("Удочка брошена ...")
    last_time = time.time() # time last fish was catched
    #...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-08-12
@jerwright

GUI events are handled by an infinite loop that starts when you call app.exec()it. It cannot be stopped or the application will hang. But your loop does exactly that, stopping the window's event loop.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question