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


基础教程推荐
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01