PyQt5 – How to get value of Progress Bar ?
In this article we will see how to get the value of progress bar. Value of the process bar is basically used to set the percentage of progress bar. Note : Percentage and value of progress bar are both different things they can have same values but percentage depends upon the range of progress bar and value of progress bar, if range of progress bar is from 0 to 100 then percentage value will be equal to value of progress bar. In order to get value of progress bar we will use value method.
Syntax : bar.value() Argument : It takes no argument. Return : It returns integer value.
Below is the implementation.
Python3
from PyQt5.QtWidgets import *
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys
class Window(QMainWindow):
def __init__( self ):
super ().__init__()
self .setWindowTitle("Python ")
self .setGeometry( 100 , 100 , 600 , 400 )
self .UiComponents()
self .show()
def UiComponents( self ):
bar = QProgressBar( self )
bar.setGeometry( 200 , 150 , 200 , 30 )
bar.setMaximum( 200 )
bar.setValue( 100 )
value = bar.value()
label = QLabel("value = " + str (value), self )
label.move( 200 , 200 )
bar.setAlignment(Qt.AlignCenter)
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
Last Updated :
23 Jan, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...