Skip to content

Instantly share code, notes, and snippets.

@bcr
Created January 10, 2023 07:38
Show Gist options
  • Save bcr/5aa24c8e4b79fe7f12f0735c4e039fa1 to your computer and use it in GitHub Desktop.
Save bcr/5aa24c8e4b79fe7f12f0735c4e039fa1 to your computer and use it in GitHub Desktop.
Simple status bar for Python
class StatusBar:
def __init__(self, max_value, max_width):
self.max_value = max_value
self.max_width = max_width
self.update(0)
def update(self, new_value):
number_markers = new_value * (self.max_width - 2) // self.max_value
marker_string = "#" * number_markers
print("\r[" + marker_string + (" " * (self.max_width - len(marker_string) - 2)) + "]", end='')
def final(self):
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment