I want to create a progress bar that shows how much progress the compression program has made. I'm a newbie, so any help would be appreciated
Asked
Active
Viewed 621 times
0
-
2please, take a look at [how-to-ask](https://stackoverflow.com/help/how-to-ask) and consider to add more details to your question – Yusef Maali May 26 '20 at 06:50
-
2Did you consider searching for `python progress bar` online? Literally hundreds of results... – Tomerikoo May 26 '20 at 07:02
-
3Does this answer your question? [Python Progress Bar](https://stackoverflow.com/questions/3160699/python-progress-bar) ; https://stackoverflow.com/questions/48573445/add-progress-bar-to-a-python-function ; https://stackoverflow.com/questions/3002085/python-to-print-out-status-bar-and-percentage ; https://stackoverflow.com/questions/3173320/text-progress-bar-in-the-console – Tomerikoo May 26 '20 at 07:02
2 Answers
1
Check out the tqdm library. It's a very active project and there are examples on the github page on how to use it.
From the above site:
Instantly make your loops show a smart progress meter - just wrap any iterable with tqdm(iterable), and you're done!
from tqdm import tqdm
for i in tqdm(range(10000)):
...
Its very easy to use and one that i would recommend.

Nick
- 3,454
- 6
- 33
- 56
0
I have a function which I have used within some of my projects. You can adapt it for your requirements:
import sys
import time
def update_progress(progress):
barLength = 56 # specify the length of your progressbar
status = ""
if isinstance(progress, int):
progress = float(progress)
if not isinstance(progress, float):
progress = 0
status = "error: progress var must be float\r\n"
if progress < 0:
progress = 0
status = "Halt...\r\n"
if progress >= 1:
progress = 1
status = "Done...\r\n"
block = int(round(barLength*progress))
text = "\rProgress: [{0}] {1}%".format( "#"*block + "-"*(barLength-block), int(progress*100))
sys.stdout.write(text)
sys.stdout.flush() # clear screen to update progress
Call it:
update_progress(0.5) # update to 50%
# do some processing #
# you might want to call sleep method if your processing doesn't take so long in order to smooth the progress update
time.sleep(2) # wait for two seconds to see progress
update_progress(1); # update to 100%
Output:
Progress: [########################################################] 100%

Tomerikoo
- 18,379
- 16
- 47
- 61

CanciuCostin
- 1,773
- 1
- 10
- 25