I want to make a loading bar like inapton thelinuxwhen downloading package files or installing them.
There somehow it is necessary to erase the lines, I was looking for this, but many scripts did not work for some reason.

those. loading is displayed in one line? And this line keeps changing

kin4stat2022-01-30 18:29:38

Yes, yes, yes, in one line.

Krutos VIP2022-01-30 18:29:38
  • Answer # 1

    try this

    import time
    from progress.bar import IncrementalBar
    mylist= [1,2,3,4,5,6,7,8]
    bar= IncrementalBar('Countdown', max= len(mylist))
    for item in mylist:

    welcome to This Club in Russian! please try to leave a little more detailed answers. You can add to your answer by clicking edit.

    aleksandr barakin2022-01-30 12:23:18
  • Answer # 2

    Personally, I do this (not using modules):

    import time
    for percent in range(100):
        s= f"[{(percent //10) * '■'}"
        s += f"{(10 -(percent //10)) * '○'}]"
        s += f"{percent}"
        print(s, end="\r")
    >>> [■■■■■■■○○○] 78

    s is broken into lines to make it easier to read. In fact, everything can be collected in one line

  • Answer # 3

    The code is not mine, but stolen from the Internet, which I use. Without additional libraries 1 function

    import time
    def printProgressBar(iteration, total, prefix= '', suffix= '', decimals= 1, length= 100, fill= '█', printEnd= "\r"):
        Call in a loop to create terminal progress bar
            iteration -Required : current iteration (Int)
            total -Required : total iterations (Int)
            prefix -Optional : prefix string (Str)
            suffix -Optional : suffix string (Str)
            decimals -Optional : positive number of decimals in percent complete (Int)
            length -Optional : character length of bar (Int)
            fill -Optional : bar fill character (Str)
            printEnd -Optional : end character (e.g. "\r", "\r\n") (Str)
        percent= ("{0:." + str(decimals) + "f}").format(100 * (iteration /float(total)))
        filledLength= int(length * iteration //total)
        bar= fill * filledLength + '-' * (length -filledLength)
        print('\r%s |%s| %s%% %s' % (prefix, bar, percent, suffix), end= printEnd)
        #Print New Line on Complete
        if iteration== total:
    #A List of Items
    items= list(range(0, 57))
    l= len(items)
    # Initial call to print 0% progress
    printProgressBar(0, l, prefix= 'Progress:', suffix= 'Complete', length= 50)
    for i, item in enumerate(items):
        # Do stuff...
        # Update Progress Bar
        printProgressBar(i + 1, l, prefix= 'Progress:', suffix= 'Complete', length= 50)
  • Answer # 4
    In [1]: from tqdm import tqdm
    In [2]: import time
    In [3]: for i in tqdm(range(10)):
       ...: time.sleep(2)
     30%|██████████████████████████████▌ | 3/10 [00:06<00:14, 2.00s/it]