📜  PyQt5 |如何设置进度条的值?

📅  最后修改于: 2022-05-13 01:55:20.336000             🧑  作者: Mango

PyQt5 |如何设置进度条的值?

在本文中,我们将看到如何设置进度条的值。进度条基本上是一个用于可视化扩展计算机操作的进度条,例如下载、文件传输或安装。

为了给进度条设置值,我们将使用setValue方法。

代码 :

# importing libraries
from PyQt5.QtWidgets import * 
from PyQt5.QtGui import * 
from PyQt5.QtCore import * 
import sys
  
  
class Window(QMainWindow):
    def __init__(self):
        super().__init__()
  
        # setting title
        self.setWindowTitle("Python ")
  
        # setting geometry
        self.setGeometry(100, 100, 600, 400)
  
        # calling method
        self.UiComponents()
  
        # showing all the widgets
        self.show()
  
    # method for widgets
    def UiComponents(self):
  
        # creating progress bar
        bar = QProgressBar(self)
  
        # setting geometry to progress bar
        bar.setGeometry(200, 150, 200, 30)
          
        # setting value to progress bar
        bar.setValue(50)
  
  
# create pyqt5 app
App = QApplication(sys.argv)
  
# create the instance of our Window
window = Window()
  
# start the app
sys.exit(App.exec())

输出 :