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


基础教程推荐
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 包装空间模型 2022-01-01
- 求两个直方图的卷积 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01