Can I add message to the tqdm progressbar? Can I add message to the tqdm progressbar? python python

Can I add message to the tqdm progressbar?


The example shown in Usage of tqdm works well for me.

pbar = tqdm(["a", "b", "c", "d"])for char in pbar:    pbar.set_description("Processing %s" % char)


You can change the description to show a small message before the progress bar, like this:

from tqdm import trangefrom time import sleept = trange(100, desc='Bar desc', leave=True)for i in t:    t.set_description("Bar desc (file %i)" % i)    t.refresh() # to show immediately the update    sleep(0.01)

/EDIT: in the latest releases of tqdm, you can use t.set_description("text", refresh=True) (which is the default) and remove t.refresh() (thanks to Daniel for the tip).


Other answers focus on dynamic description, but for a static description you can add a desc argument into the tqdm function.

from tqdm import tqdmx = [5]*1000for _ in tqdm(x, desc="Example"):    pass Example: 100%|██████████████████████████████████| 1000/1000 [00:00<00:00, 1838800.53it/s]