Python 如何获取pyQt5中ProgressBar的当前值?

Python 如何获取pyQt5中ProgressBar的当前值?,python,progress-bar,pyqt5,Python,Progress Bar,Pyqt5,我正在学习Pyqt5。 问题是我想得到pyqt5中progressbar的值 我尝试使用self.progressBar.getValue()或self.progressBar.getInt()它们都不起作用 实际代码有点大,但没关系。请帮忙 我只需要从progressbar获取当前值的语法,即:1到100之间,根据它们的语法,获取值的方法就是Value(),因此在您的情况下,它将是self.progressbar.Value()我同意@dustin we,这里是一个最小的代码示例: impor

我正在学习Pyqt5。 问题是我想得到pyqt5中progressbar的值

我尝试使用
self.progressBar.getValue()
self.progressBar.getInt()
它们都不起作用

实际代码有点大,但没关系。请帮忙


我只需要从progressbar获取当前值的语法,即:1到100之间,根据它们的语法,获取值的方法就是
Value()
,因此在您的情况下,它将是
self.progressbar.Value()

我同意@dustin we,这里是一个最小的代码示例:

import sys
import time

from PyQt5.QtWidgets import (QApplication, QDialog,
                             QProgressBar, QPushButton)

TIME_LIMIT = 100


class Actions(QDialog):
    """
    Simple dialog that consists of a Progress Bar and a Button.
    Clicking on the button results in the start of a timer and
    updates the progress bar.
    """

    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle('Progress Bar')
        self.progress = QProgressBar(self)
        self.progress.setGeometry(0, 0, 300, 25)
        self.progress.setMaximum(100)
        self.button = QPushButton('Start', self)
        self.button.move(0, 30)
        self.show()

        self.button.clicked.connect(self.onButtonClick)

    def onButtonClick(self):
        count = 0
        while count < TIME_LIMIT:
            count += 1
            time.sleep(0.01)
            self.progress.setValue(count)

            # !! Here is the command you need !!
            print(self.progress.value())


if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = Actions()
    sys.exit(app.exec_())
导入系统 导入时间 从PyQt5.QtWidgets导入(QApplication、QDialog、, QpressBar、QPushButton) 时限=100 集体诉讼(QDialog): """ 由进度条和按钮组成的简单对话框。 单击该按钮会启动计时器,然后 更新进度条。 """ 定义初始化(自): super()。\uuuu init\uuuuu() self.initUI() def initUI(self): self.setWindowTitle(“进度条”) self.progress=QProgressBar(self) self.progress.setGeometry(0,0,300,25) self.progress.setMaximum(100) self.button=QPushButton('Start',self) 自动按钮移动(0,30) self.show() self.button.clicked.connect(self.onButtonClick) def ON按钮单击(自身): 计数=0 计数<时间限制: 计数+=1 睡眠时间(0.01) self.progress.setValue(计数) # !! 这是你需要的命令!! 打印(self.progress.value()) 如果名称=“\uuuuu main\uuuuuuuu”: app=QApplication(sys.argv) 窗口=操作() sys.exit(app.exec_())
谢谢……我的坏……在愚蠢的互联网上找不到这么简单的属性
value()
。。。