PyQt5 – format() method for Progress bar

We can set the formatting and and show text using setFormat method in Progress Bar, format method is used to get the formatting of the progress bar.

Note : By default formatting of progress bar is ‘%p%’ i.e used to print percentage, so if no specific formatting is set format method will return ‘%p%’.

Syntax : bar.format()

Argument : It takes no argument.

Return : It return string.



Below is the implementation of this method.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing libraries
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__()
  
        # 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
        bar1 = QProgressBar(self)
  
        # setting geometry to progress bar
        bar1.setGeometry(200, 100, 200, 30)
  
        # setting the value
        bar1.setValue(70)
  
        # getting format of bar1
        format1 = bar1.format()
  
        # printing the format1
        print("format of bar 1 : " + format1)
  
        bar2 = QProgressBar(self)
  
        # setting geometry to progress bar
        bar2.setGeometry(200, 200, 200, 30)
  
        # setting the value
        bar2.setValue(50)
  
        # setting text using format
        bar2.setFormat("Geeks")
  
        # getting format of bar2
        format2 = bar2.format()
  
        # printing the format2
        print("format of bar 2 : " + format2)
  
  
App = QApplication(sys.argv)
  
# create the instance of our Window
window = Window()
  
# start the app
sys.exit(App.exec())

chevron_right


Output :

format of bar 1 : %p%
format of bar 2 : Geeks

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.