Understandably, we get a little impatient when we do not know how much time a process is going to take, for example, a for loop or a file downloading or an application starting up. To distract us from that we were given the libraries tqdm and progressbar in Python language which allows us to give a visual illustration of the process completion time using a progress bar. Loading bars are often seen on game screens as the resources required for the game to run are being acquired to the main memory.
Using tqdm
What It Does
It wraps an iterable with the tqdm to decorate it with the methods built-in with tqdm and make a loading bar. This will take the users’ mind off of how long the process is taking to complete.
How To Use
All we need to do is, install the tqdm package by typing this line in your terminal and start writing the code.
->pip install tqdm
And type this code in your editor.
Python3
from tqdm import tqdm
for i in tqdm ( range ( 100 ), desc = "Loading..."):
pass
|
Output:
This gives a very fast loading bar because there’s nothing in the loop., you can replace the pass keyword with whatever work you want to do in the for loop.
Python3
from tqdm import tqdm
import time
for i in tqdm ( range ( 101 ),
desc = "Loading…",
ascii = False , ncols = 75 ):
time.sleep( 0.01 )
print ("Complete.")
|
Output: 
Using progressbar
How To Install
For command-line interface
pip install progressbar
(or)
pip install progressbar2
Working
It does everything the same as tqdm package, that is it decorates the iterable with the built-in widgets to make an animated progress bar or even a colorful one. Widgets are objects which display depending on the progress bar. However, the progress bar and the progress bar 2 packages have a lot of extra, useful methods than the tqdm package. For example, we can make an animated loading bar.
Python3
import progressbar
import time
def animated_marker():
widgets = [ 'Loading: ' , progressbar.AnimatedMarker()]
bar = progressbar.ProgressBar(widgets = widgets).start()
for i in range ( 50 ):
time.sleep( 0.1 )
bar.update(i)
animated_marker()
|
Output:
In progressbar.AnimatedMarker(), we can pass any sequence of characters to animate. The default arguments are ‘|/-\|’ Here’s another example using some of the commonly used widgets of the ProgressBar class.
Python3
import time
import progressbar
widgets = [ ' [' ,
progressbar.Timer( format = 'elapsed time: %(elapsed)s' ),
'] ' ,
progressbar.Bar( '*' ), ' (' ,
progressbar.ETA(), ') ' ,
]
bar = progressbar.ProgressBar(max_value = 200 ,
widgets = widgets).start()
for i in range ( 200 ):
time.sleep( 0.1 )
bar.update(i)
|
Output: 
Using sys and time
Prerequisites:
Functions and variables for modifying many elements of the Python runtime environment are available in the sys module.
The following code can be used to import this built-in module without having to install it first:
import sys
Accessing time in Python is made possible by the time module. It has capabilities like the ability to delay the execution of the application and the ability to get the current date and time. This module needs to be imported before we can start using its features.
This is an in-built module and need not be installed, it can be imported directly using the code:
import time
Python comes with a built-in module called Python Random that may be used to create random integers. Since they are not completely random, these numbers are pseudo-random. This module may be utilized to carry out random operations like generating random integers, printing a random value for a list or string, etc.
It is not necessary to install this built-in module because it may be imported directly using the following code:
import random
Code:
Python3
import sys,time,random
def progressBar(count_value, total, suffix = ''):
bar_length = 100
filled_up_Length = int ( round (bar_length * count_value / float (total)))
percentage = round ( 100.0 * count_value / float (total), 1 )
bar = '=' * filled_up_Length + '-' * (bar_length - filled_up_Length)
sys.stdout.write( '[%s] %s%s ...%s\r' % (bar, percentage, '%' , suffix))
sys.stdout.flush()
for i in range ( 11 ):
time.sleep(random.random())
progressBar(i, 10 )
|
Output:

Output in Terminal Window
Similar Reads
Backward iteration in Python
Backward iteration in Python is traversing a sequence (like list, string etc.) in reverse order, moving from the last element to the first. Python provides various methods for backward iteration, such as using negative indexing or employing built-in functions like reversed(). Using reversed() method
2 min read
Python Program to Find Sum of Array
Given an array of integers, find the sum of its elements. Examples: Input : arr[] = {1, 2, 3}Output : 6Explanation: 1 + 2 + 3 = 6This Python program calculates the sum of an array by iterating through each element and adding it to a running total. The sum is then returned. An example usage is provid
4 min read
Running Python program in the background
Let us see how to run a Python program or project in the background i.e. the program will start running from the moment device is on and stop at shut down or when you close it. Just run one time to assure the program is error-bug free One way is to use pythonw, pythonw is the concatenation of python
3 min read
Python Program for Simple Interest
The task of calculating Simple Interest in Python involves taking inputs for principal amount, time period in years, and rate of interest per annum, applying the Simple Interest formula and displaying the result. For example, if p = 1000, t = 2 (years), and r = 5%, the Simple Interest is calculated
3 min read
Python Program for Compound Interest
Let us discuss the formula for compound interest. The formula to calculate compound interest annually is given by: A = P(1 + R/100) t Compound Interest = A - P Where, A is amount P is the principal amount R is the rate and T is the time spanFind Compound Interest with Python C/C++ Code # Python3 pro
3 min read
Output of Python programs | Set 8
Prerequisite - Lists in Python Predict the output of the following Python programs. Program 1 [GFGTABS] Python list = [1, 2, 3, None, (1, 2, 3, 4, 5), ['Geeks', 'for', 'Geeks']] print len(list) [/GFGTABS]Output: 6Explanation: The beauty of python list datatype is that within
3 min read
Python Coding Practice Problems
This collection of Python coding practice problems is designed to help you improve your overall programming skills in Python. The links below lead to different topic pages, each containing coding problems, and this page also includes links to quizzes. You need to log in first to write your code. You
1 min read
Output of Python programs | Set 7
Prerequisite - Strings in Python Predict the output of the following Python programs. These question set will make you conversant with String Concepts in Python programming language. Program 1[GFGTABS] Python var1 = 'Hello Geeks!' var2 = "GeeksforGeeks" print "var1[0]: ",
3 min read
Python Program for Counting Sort
Counting sort is a sorting technique based on keys between a specific range. It works by counting the number of objects having distinct key values (kind of hashing). Then doing some arithmetic to calculate the position of each object in the output sequence. C/C++ Code # Python program for counting s
2 min read
Python Basics Quizzes
This quiz is designed to help you practice essential Python concepts, including Fundamentals, Input/Output, Data Types, Numbers, Boolean, Control Flow and Loops. By solving these problems, you'll strengthen your understanding of Python's core building blocks and gain confidence in applying them. Let
1 min read