PyQt5 – How to get percentage of Progress Bar ?
Last Updated :
22 Apr, 2020
In this article we will see how to get the percentage value of progress bar, we can set the percentage of progress bar using setValue
method. In order to get the percentage value we use text
method which will return the integer that indicates the percentage.
Syntax : bar.text()
Argument : It takes no argument.
Return : It return integer.
Below is the implementation.
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.setValue( 70 )
p_value = bar.text()
label = QLabel( "percentage = " + str (p_value), self )
label.move( 200 , 200 )
bar.setAlignment(Qt.AlignCenter)
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...