Floodgauge
ttkbootstrap.widgets.Floodgauge (Progressbar)
A widget that shows the status of a long-running operation with an optional text indicator.
Similar to the ttk.Progressbar
, this widget can operate in
two modes. determinate mode shows the amount completed
relative to the total amount of work to be done, and
indeterminate mode provides an animated display to let the
user know that something is happening.
Variable are generated automatically for this widget and can be
linked to other widgets by referencing them via the
textvariable
and variable
attributes.
Examples:
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
app = ttk.Window(size=(500, 500))
gauge = ttk.Floodgauge(
bootstyle=INFO,
font=(None, 24, 'bold'),
mask='Memory Used {}%',
)
gauge.pack(fill=BOTH, expand=YES, padx=10, pady=10)
# autoincrement the gauge
gauge.start()
# stop the autoincrement
gauge.stop()
# manually update the gauge value
gauge.configure(value=25)
# increment the value by 10 steps
gauge.step(10)
app.mainloop()
__init__(self, master=None, cursor=None, font=None, length=None, maximum=100, mode='determinate', orient='horizontal', bootstyle='primary', takefocus=False, text=None, value=0, mask=None, **kwargs)
special
Parameters:
Name | Type | Description | Default |
---|---|---|---|
master |
Widget |
Parent widget. Defaults to None. |
None |
cursor |
str |
The cursor that will appear when the mouse is over the progress bar. Defaults to None. |
None |
font |
Union[Font, str] |
The font to use for the progress bar label. |
None |
length |
int |
Specifies the length of the long axis of the progress bar (width if orient = horizontal, height if if vertical); |
None |
maximum |
float |
A floating point number specifying the maximum |
100 |
mode |
'determinate', 'indeterminate' |
Use |
'determinate' |
orient |
'horizontal', 'vertical' |
Specifies the orientation of the widget. |
'horizontal' |
bootstyle |
str |
The style used to render the widget. Options include primary, secondary, success, info, warning, danger, light, dark. |
'primary' |
takefocus |
bool |
This widget is not included in focus traversal by default.
To add the widget to focus traversal, use
|
False |
text |
str |
A string of text to be displayed in the Floodgauge label.
This is assigned to the attribute |
None |
value |
float |
The current value of the progressbar. In |
0 |
mask |
str |
A string format that can be used to update the Floodgauge
label every time the value is updated. For example, the
string "{}% Storage Used" with a widget value of 45 would
show "45% Storage Used" on the Floodgauge label. If a
mask is set, then the |
None |
**kwargs |
Other configuration options from the option database. |
{} |
Source code in ttkbootstrap/widgets.py
def __init__(
self,
master=None,
cursor=None,
font=None,
length=None,
maximum=100,
mode=DETERMINATE,
orient=HORIZONTAL,
bootstyle=PRIMARY,
takefocus=False,
text=None,
value=0,
mask=None,
**kwargs,
):
"""
Parameters:
master (Widget, optional):
Parent widget. Defaults to None.
cursor (str, optional):
The cursor that will appear when the mouse is over the
progress bar. Defaults to None.
font (Union[Font, str], optional):
The font to use for the progress bar label.
length (int, optional):
Specifies the length of the long axis of the progress bar
(width if orient = horizontal, height if if vertical);
maximum (float, optional):
A floating point number specifying the maximum `value`.
Defaults to 100.
mode ('determinate', 'indeterminate'):
Use `indeterminate` if you cannot accurately measure the
relative progress of the underlying process. In this mode,
a rectangle bounces back and forth between the ends of the
widget once you use the `Floodgauge.start()` method.
Otherwise, use `determinate` if the relative progress can be
calculated in advance.
orient ('horizontal', 'vertical'):
Specifies the orientation of the widget.
bootstyle (str, optional):
The style used to render the widget. Options include
primary, secondary, success, info, warning, danger, light,
dark.
takefocus (bool, optional):
This widget is not included in focus traversal by default.
To add the widget to focus traversal, use
`takefocus=True`.
text (str, optional):
A string of text to be displayed in the Floodgauge label.
This is assigned to the attribute `Floodgauge.textvariable`
value (float, optional):
The current value of the progressbar. In `determinate`
mode, this represents the amount of work completed. In
`indeterminate` mode, it is interpreted modulo `maximum`;
that is, the progress bar completes one "cycle" when the
`value` increases by `maximum`.
mask (str, optional):
A string format that can be used to update the Floodgauge
label every time the value is updated. For example, the
string "{}% Storage Used" with a widget value of 45 would
show "45% Storage Used" on the Floodgauge label. If a
mask is set, then the `text` option is ignored.
**kwargs:
Other configuration options from the option database.
"""
# progress bar value variable
self.variable = tk.IntVar(value=value)
self.textvariable = tk.StringVar(value=text)
self._bootstyle = bootstyle
self._font = font or "helvetica 10"
self._mask = mask
self._traceid = None
super().__init__(
master=master,
class_="Floodgauge",
cursor=cursor,
length=length,
maximum=maximum,
mode=mode,
orient=orient,
bootstyle=bootstyle,
takefocus=takefocus,
variable=self.variable,
**kwargs,
)
self._set_widget_text(self.textvariable.get())
self.bind("<<ThemeChanged>>", self._on_theme_change)
self.bind("<<Configure>>", self._on_theme_change)
if self._mask is not None:
self._set_mask()
configure(self, cnf=None, **kwargs)
Configure the options for this widget.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cnf |
Dict[str, Any] |
A dictionary of configuration options. |
None |
**kwargs |
Optional keyword arguments. |
{} |
Source code in ttkbootstrap/widgets.py
def configure(self, cnf=None, **kwargs):
"""Configure the options for this widget.
Parameters:
cnf (Dict[str, Any], optional):
A dictionary of configuration options.
**kwargs:
Optional keyword arguments.
"""
if cnf is not None:
return self._configure_get(cnf)
else:
self._configure_set(**kwargs)