0

I saw many different codes and examples with progression bar. However none of them shows it in a UI format. It only shows it in the IDE which is not going to work if the user is not going to the IDE to run it. I don't have PYQT so I can't use it to create progress bar in that way. Are there any other ways to create progression bar that a user can see it after running the program, not via IDE.

tripleee
  • 175,061
  • 34
  • 275
  • 318
Johnseito
  • 315
  • 1
  • 9
  • 24

2 Answers2

1

Here is some code for a very basic text progress bar:

class progressBar():
    def __init__(self, title, length=40):
        self.BAR_LENGTH = length
        self.title = title
        print('{}\t['.format(self.title) + ' ' * self.BAR_LENGTH + ']', end='')

    def update(self, val):
        # round from 0 to self.BAR_LENGTH
        bars = round(val * self.BAR_LENGTH)
        print('\r{}\t['.format(self.title) + '#' * bars + ' ' * (self.BAR_LENGTH - bars) + ']\t{0:.2f}%'.format(
            val * 100), end='')

    def close(self):
        print('')

You use it like this:

bar = progressBar("Text beside progress bar")
while myLoopCondition == True
     # loop that you want to show progress of
    ...
    bar.update(new percentage) # decimal number from 0-1
bar.close()

Whatever program you use to make your executable should have a way of displaying a terminal when you run the program.

You should look into getting pyqt for this though

jacoblaw
  • 1,263
  • 9
  • 9
  • That is not something I can answer with the info you gave. Put it wherever seems appropriate i guess – jacoblaw Jul 25 '17 at 23:45
0

You could use the tqdm library.

You only need to modify your loop to include a counter, see this example:

from tqdm import tqdm
import time

startTime = time.clock()
totalCount = len(listOfItems)
for index, item in enumerate(listOfItems):
    stopTime = time.clock()
    statusBarText = tqdm.format_meter(index + 1,
                                      totalCount,
                                      stopTime - startTime,
                                      ncols=80,  # prints text 80 characters wide
                                      ascii=False)
    print(statusBarText, '\b' * 81, end='')
    startTime = time.clock()
    ... rest of the code in your loop goes here ...