Created
January 10, 2023 07:38
-
-
Save bcr/5aa24c8e4b79fe7f12f0735c4e039fa1 to your computer and use it in GitHub Desktop.
Simple status bar for Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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