Bar¶
Bar draws a classic fill-style progress bar.
The default choice for a determinate task with a known total: a marker
fills the line from left to right as value approaches max_value.
marker, left, right, and fill set the characters drawn,
and fill_left picks the side the padding sits on.
- class progressbar.widgets.Bar(marker='#', left='|', right='|', fill=' ', fill_left=True, marker_wrap=None, **kwargs)[source]
Bases:
AutoWidthWidgetBaseA progress bar which stretches to fill the line.
Create the bar with its marker and border characters.
- Parameters:
marker – Character, or (progress, data, width) -> str callable, used for the filled portion.
left – Character, or callable, used as the left border.
right – Character, or callable, used as the right border.
fill – Character used for the empty part of the bar.
fill_left – Fill/grow from the left. If False, from the right.
marker_wrap – Begin/end strings or template wrapped around a string marker (see create_wrapper). Ignored for a callable marker.
**kwargs – Forwarded to the next class in the cooperative __init__ chain.
Example¶
"""``Bar`` draws a classic fill-style progress bar.
The default choice for a determinate task with a known total: a marker
fills the line from left to right as ``value`` approaches ``max_value``.
See ``ReverseBar`` for the mirrored direction, ``GranularBar`` for
sub-character precision, and ``BouncingBar`` for indeterminate work.
"""
import time
import progressbar
STEPS = 24
def main() -> None:
widgets = [progressbar.Percentage(), ' ', progressbar.Bar()]
with progressbar.ProgressBar(max_value=STEPS, widgets=widgets) as bar:
for step in range(STEPS):
bar.update(step + 1)
time.sleep(0.005)
if __name__ == '__main__':
main()
See also¶
ReverseBar: the same bar filling right to left.
GranularBar: sub-character resolution.
BouncingBar: an indeterminate variant for unknown totals.