Python – Create progress bar using tqdm module

In this article we will see how to make progress bar with the help of tqdm module. A progress bar is a graphical control element used to visualize the progression of an extended computer operation, such as a download, file transfer, or installation. Sometimes, the graphic is accompanied by a textual representation of the progress in a percent format.

Required Modules :

Tqdm : Tqdm package is one of the more comprehensive packages for progress bars with python and is handy for those instances you want to build scripts that keep the users informed on the status of your application.

pip install tqdm

Time : This module provides various time-related functions, it is part of python’s standard library.

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

# importing modules
from tqdm import trange
from time import sleep
   
# creating loop
for i in trange(10, desc ="loop "):
           
        # slowing the for loop
        sleep(0.1)

chevron_right


Output :

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing modules
from tqdm import tnrange
from time import sleep
  
# creating loop
for i in tnrange(2, desc ="loop 1"):
      
    # creating nested loop
    for j in tnrange(5, desc ="loop 2"):
          
        # slowing the for loop
        sleep(0.2)

chevron_right


Output :

Example 3:

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing modules
import time
import sys
from tqdm import trange
  
# random function
def random_task():
    time.sleep(0.5)    
  
# another random function
def another_random_task():
    time.sleep(0.2)
  
# Outer loop
for i in trange(3, file=sys.stdout, desc='Outer loop'):
    random_task()
      
    # inner loop
    for j in trange(5,file=sys.stdout, desc='Inner loop'):
        another_random_task()

chevron_right


Output :




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.