AnimatedMarker¶
AnimatedMarker cycles through characters and colours to show a spinner.
Reach for it for indeterminate work where there is nothing to measure a
percentage against, just a signal that the process is still alive.
Unlike Bar, it does not grow or fill: it replaces one character each
redraw. markers sets the cycle of characters (default |/-\).
- class progressbar.widgets.AnimatedMarker(markers: str = '|/-\\', default: str | None = None, fill: str = '', marker_wrap: str | tuple[str | None, str | None] | None = None, fill_wrap: str | tuple[str | None, str | None] | None = None, color_cycle: int | None = None, **kwargs: Any)[source]
Bases:
TimeSensitiveWidgetBaseAn animated marker that cycles through frames and colours by default.
Every redraw advances the frame by one character and the colour by one step around colors.rainbow, taking color_cycle redraws for a full lap. The colour follows the redraw count, not progress, so it keeps moving on indeterminate bars too.
Create an AnimatedMarker.
- Parameters:
markers – Sequence of single-character frames cycled through on every redraw.
default – Frame shown once finished when fill is unset; defaults to markers[0].
fill – Marker character/callable used to pad the frame to width (see create_marker). Unset means no filling.
marker_wrap – Begin/end strings or template wrapped around the marker frame (see create_wrapper).
fill_wrap – Same as marker_wrap, for the fill.
color_cycle – Redraws per full lap around the colour gradient. Defaults to the class-level color_cycle (30, twelve degrees of hue per redraw).
**kwargs – Forwarded to the next class in the cooperative __init__ chain.
- color_cycle: int = 30
Redraws per full lap around the colour gradient.
Example¶
"""``AnimatedMarker`` cycles through characters to show a spinner.
Reach for it for indeterminate work where there is nothing to measure a
percentage against -- just a signal that the process is still alive.
Unlike ``Bar``, it does not grow or fill; it only replaces one character
each redraw.
"""
import time
import progressbar
STEPS = 24
def main() -> None:
widgets = ['Working: ', progressbar.AnimatedMarker()]
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()
The default spinner advances one character and one step around the
rainbow on every redraw, a full lap every 30 redraws. Pass
color_cycle to make the lap longer or shorter. No colour
configuration is needed.
See also¶
Bar: a fill bar, for when a total is known.
BouncingBar: a full-width bouncing marker, also indeterminate.
RotatingMarker: the legacy name for this same widget.