Python | How to make a terminal progress bar using tqdm
Last Updated :
12 Nov, 2024
Whether you’re installing software, loading a page, or doing a transaction, it always eases your mind whenever you see that small progress bar giving you an estimation of how long the process would take to complete or render. If you have a simple progress bar in your script or code, it looks very pleasing to the eye and gives proper feedback to the user whenever they execute the code. You can use the Python external library tqdm, to create simple & hassle-free progress bars which you can add to your code and make it look lively!
Installation
Open your command prompt or terminal and type:
pip install tqdm
If you are using Python3 then type:
pip3 install tqdm
This command would successfully install the library on your computer and is now ready to use.
Usage
Using tqdm is very simple, you just need to add your code between tqdm() after importing the library in your code. You need to make sure that the code you put in between the tqdm() function must be iterable or it would not work at all.
Let us see the following example that would help you understand better:
Example:
Python
from tqdm import tqdm
for i in tqdm(range(int(9e6))):
pass
Output:

Now that we know how to implement tqdm, let’s take a look at some of the important parameters it offers and how it can be used to tweak the progress bar.
- desc: You can use this parameter to specify the description of your progress bar as follows:
Syntax:
tqdm (self, iterable, desc= “Text You want”)
Example:
Python
from tqdm import tqdm
from time import sleep
for i in tqdm(range(0, 100), desc="Text You Want"):
sleep(0.1)
Output:

- total: This is used to specify the total number of expected iterations if not specified already or needs modification.
Syntax:
tqdm (self, iterable, total= 500)
Example:
Python
from tqdm import tqdm
from time import sleep
for i in tqdm(range(0, 100), total=500, desc="Text You Want"):
sleep(0.1)
Output:

- disable: This parameter can be used if you want to completely disable the progress bar.
Syntax:
tqdm (self, iterable, disable=True)
Example:
Python
from tqdm import tqdm
from time import sleep
for i in tqdm(range(0, 100), disable=True, desc="Text You Want"):
sleep(0.1)
print("Iteration Successful")
Output:

- ncols: This parameter is used to specify the entire width of the output message. If left unspecified it remains dynamic to the size of the window. This can be fixed through the ncols parameter.
Syntax:
tqdm (self, iterable, ncols= 100)
Example:
Python
from tqdm import tqdm
from time import sleep
for i in tqdm(range(0, 100), ncols=100, desc="Text You Want"):
sleep(0.1)
Output:

- mininterval: You can easily change the minimum progress display update using this option. The default is to 0.1 seconds.
Syntax:
tqdm (self, iterable, mininterval=3)
Example:
Python
from tqdm import tqdm
from time import sleep
for i in tqdm(range(0, 100), mininterval=3, desc="Text You Want"):
sleep(0.1)
Output:

- ascii: You can use ASCII characters to fill the progress bar as per your liking.
Syntax:
tqdm (self, iterable, ascii= “123456789$”, desc="Text You Want")
Example:
Python
from tqdm import tqdm
from time import sleep
for i in tqdm(range(0, 100), ascii="123456789$"):
sleep(0.1)
Output:

- unit: The default unit of time is “it” and can be changed by using this parameter to your preferred unit.
Syntax:
tqdm (self, iterable, unit= “ ticks”)
Example:
Python
from tqdm import tqdm
from time import sleep
for i in tqdm(range(0, 100), unit=" ticks", desc="Text You Want"):
sleep(0.1)
Output:

- initial
The initial value of the progress bar starts from 0. If you wish to change this, you can use this parameter to initialize the progress bar from the value you wish
Syntax:
tqdm (self, iterable, initial=50)
Example:
Python
from tqdm import tqdm
from time import sleep
for i in tqdm(range(0, 100), initial=50, desc="Text You Want"):
sleep(0.1)
Output:
Similar Reads
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
2 min read
Display Images on Terminal using Python
In this article, we will discuss how to display images on a terminal using Python. We will be using the climage module for the same. This module has the following features -Â It helps to convert images to its ANSI Escape Codes to be able to convert be printable on Command-Line Interfaces.It allows 8
3 min read
PyQt5 | How to set value of Progress Bar ?
In this article we will see how to set the value of progress bar. Progress bar is basically a bar which is used to visualize the progression of an extended computer operation, such as a download, file transfer, or installation. In order to set value to progress bar we will use setValue method. Synta
1 min read
PyQt5 - How to set text to progress bar ?
In this article we will see how to set text to progress bar. When we create a progress bar only progress percentage text is visible but we can also set some text on it. Below is how normal progress bar vs progress bar with text looks like. In order to do this we will use setFormat method, although i
1 min read
PyQt5 - How to add margin in Progress Bar
In this article we will see how to set margin to a progress bar. In order to add margin to progress bar we have to change the style sheet code for the chunk i.e the internal part (loading bar) of the progress bar. Below is the style sheet code. QProgressBar::chunk { background-color: pink; margin: 5
1 min read
PyQt5 - How to set the maximum value of progress bar ?
In this article we will see how to set the maximum value of progress bar. By default the maximum value of progress bar is 100, but we can change it to our need. In order to do this we will use setMaximum method, this will change the maximum value of progress bar. Note : When we will set the value to
2 min read
Python | Progress Bar widget in kivy
Kivy is a platform-independent GUI tool in Python. As it can be run on Android, IOS, linux and Windows etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktops applications. 👉🏽 Kivy Tutorial - Learn Kivy with Examples. Pro
4 min read
PyQt5 - Skin to Bar of Progress Bar
In this article we will see how to set the skin to the bar of progress bar. Skin is basically a background image but it adjust it self to the size of bar of progress bar. Below is the representation of bar of progress bar with background image and bar of progress bar with skin. In order to do this w
2 min read
PyQt5 - Translucent Bar of Progress Bar
In this article we will see how to make the bar translucent i.e in between opaque and transparent. The progress bar have two components one is the background which is visible when bar is not at 100% other is the bar which tells the progress, when we make bar translucent the background will be visibl
2 min read
PyQt5 - How to set minimum value of progress bar ?
In this article we will see how to set the minimum value of progress bar. By default the minimum value of progress bar is 0, but we can change it to our need. In order to do this we will use setMinimum method, this will change the maximum value of progress bar. If we change the minimum value, percen
2 min read