Python PyQt4 进度条卡住 GUI

标签 python progress-bar pyqt4 freeze

下面的代码对一堆 PyQt4 进度条进行了计数,达到 99%,我希望我的 GUI 不要 卡住,因为它们计数到了 99%。如果可能的话,我希望不使用自定义类或函数来做到这一点。 我知道使用类很好,但是对于这个小代码片段,我不想创建一个类。 根据我所读到的内容,可能有一个 update() 函数可以完成此任务...请告知我是否走在正确的轨道上

import sys
import time
from PyQt4 import QtGui
from PyQt4 import QtCore


app = QtGui.QApplication(sys.argv)

widget = QtGui.QWidget()
widget.resize(400, 200)
widget.setWindowTitle('simple')
widget.show()

shift = 0
cntControl = 5
barra = [0] * cntControl
for i in range(cntControl):
    shift = shift + 10
    barra[i] = QtGui.QProgressBar(widget)
    barra[i].show()
    barra[i].setMinimum(0)
    barra[i].setMaximum(10000)
    barra[i].setGeometry(QtCore.QRect(10, shift, 200, 10))


for a in range(10000):
    for i in range(cntControl):
        barra[i].setValue(a)



sys.exit(app.exec_())

最佳答案

尝试更改 for 循环:

while True:
    for a in range(10000):
        time.sleep(0.0001)
        for i in range(cntControl):
            barra[i].setValue(a)

如果对我有用。 while 循环继续不断地移动酒吧。如果您只想在到达终点后清理栏,您应该使用重置:

PySide.QtGui.QProgressBar.reset()
Reset the progress bar. The progress bar “rewinds” and shows no
progress

OP 评论后更新:如果您希望 gui 在进入长循环或其他操作时做出响应,您应该使用 python thread moduleQThreads .

关于Python PyQt4 进度条卡住 GUI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5743008/

相关文章:

python - vagrant pip 安装 svn+https ://. 。身份验证失败,交互式提示被禁用

Python:像 quartz 一样的事件调度

python - 如何为 PyQt 安装新的 QStyle?

python - 当模式包含重复项时如何在python中顺序替换模式

Python - 将列表列表划分为组

javascript - 使用javascript在python循环中更新HTML

javascript - 如何在每次循环内调用小程序方法时更新进度条(不仅仅是循环完成时)?

c# - backgroundWorker 和 progressChanged 不工作

python - PyQT中事件的识别源

python - PyQt QSpinBox 更新范围取决于其他 spinbox 的值