相当于 PyQt 应用程序的 time.sleep

Equivalent to time.sleep for a PyQt application(相当于 PyQt 应用程序的 time.sleep)

本文介绍了相当于 PyQt 应用程序的 time.sleep的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在我的 pyqt 应用程序中使用 time.sleep,因为这会冻结 GUI 线程,因此在此期间 GUI 将完全冻结.我一直在寻找处理此问题的方法.

I can't use time.sleep in my pyqt application because that freezes the GUI thread, so the GUI will be completely frozen during this time.I have been looking for a way to handle this.

我尝试使用 QTimer,但似乎需要将它们链接到另一个函数?像等待十秒钟然后运行一些功能.有没有办法让它等待然后继续当前的功能?

I tried to use QTimer, but it seemed like they need to be linked to another function? Like wait ten seconds then run some function. Is there a way to just have it wait then continue with the current function?

def num(self):
    for i in range(1,999):
        print i
        #Add some sleep here

def testSleep(self):
    QtCore.QTimer.singleShot(2000, self.num)

推荐答案

实际上我正在寻找 time.sleep 替代方案以在 pyqt 中使用而不使用任何线程概念.

Actually i was looking for time.sleep alternative to use in pyqt without using any thread concepts.

我想出的解决方案是:

from PyQt4 import QtTest

QtTest.QTest.qWait(msecs)

这类似于 time.sleep 使 GUI 响应.

This works similar to time.sleep making GUI responsive.

感谢您的回答.

这篇关于相当于 PyQt 应用程序的 time.sleep的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:相当于 PyQt 应用程序的 time.sleep

基础教程推荐