FormatLabelBar

FormatLabelBar centers a formatted label inside a fill bar.

Reach for it to combine Bar and FormatLabel in one widget: the label sits centered over the fill instead of beside it. format reads the same data snapshot as FormatLabel.

class progressbar.widgets.FormatLabelBar(format, **kwargs: Any)[source]

Bases: FormatLabel, Bar

A bar which has a formatted label in the center.

Create a FormatLabelBar with the given format string.

Parameters:
  • format – The label template (see FormatLabel).

  • **kwargs – Forwarded to Bar.__init__.

Example

FormatLabelBar
"""``FormatLabelBar`` centers a formatted label inside a fill bar.

Reach for it to combine ``Bar`` and ``FormatLabel`` in one widget -- the
label sits centered over the fill instead of beside it. See
``PercentageLabelBar`` for the common case of centering the percentage
specifically.
"""

import time

import progressbar

STEPS = 24


def main() -> None:
    widgets = [progressbar.FormatLabelBar('%(value)d of %(max_value)d')]
    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

  • Bar: the plain fill bar this combines with a label.

  • FormatLabel: the label formatting this centers over the fill.

  • PercentageLabelBar: the common case, a centered percentage.