Equivalent to time.sleep for a PyQt application(相当于 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
基础教程推荐
- 尝试制作WhatsApp机器人 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
