DynamicMessage¶
DynamicMessage is the original name for Variable.
Same widget, kept as an alias for code written against the old name.
Prefer Variable in new code.
- class progressbar.widgets.DynamicMessage(name, format='{name}: {formatted_value}', width=6, precision=3, **kwargs)[source]
Bases:
VariableLegacy alias for Variable. Prefer Variable in new code.
Kept as a plain subclass (no DeprecationWarning) until the next major version.
Create a Variable rendering the bar variable name.
- Parameters:
name – data[‘variables’] key to read (see VariableMixin).
format – str.format() template. Besides the usual keys it gets name, value, width, precision, and formatted_value (value formatted per width/ precision if numeric, else ‘-’ * width if falsy).
width – Minimum field width used to format a numeric value.
precision – Decimal precision used to format a numeric value.
**kwargs – Forwarded to the next class in the cooperative __init__ chain.
Example¶
"""``DynamicMessage`` is the original name for ``Variable``.
Same widget, kept as an alias for code written against the old name;
prefer ``Variable`` in new code. Shown here in its classic role: a live
training metric climbing toward its target, reported next to the bar.
"""
import random
import time
import progressbar
random.seed(0)
STEPS = 24
def main() -> None:
widgets = [
progressbar.Percentage(),
' ',
progressbar.Bar(),
' ',
progressbar.DynamicMessage('accuracy'),
]
with progressbar.ProgressBar(max_value=STEPS, widgets=widgets) as bar:
accuracy = 0.5
for step in range(STEPS):
accuracy += (1 - accuracy) * (0.05 + random.random() * 0.05)
bar.update(step + 1, accuracy=accuracy)
time.sleep(0.005)
if __name__ == '__main__':
main()
See also¶
Variable: the current name for this widget.