beetlebug▾
/

ttk::progressbar

Makes a themed progress bar: a bar that shows how much of a task is done, or that a task runs.

ttk::progressbar PATHNAME ?OPTION VALUE ...?

Description

Makes a themed progress bar with the name PATHNAME and the options of the call, and makes the command PATHNAME for the widget commands below. The bar has a track and a bar inside it.

In the mode determinate, the bar fills the fraction -value / -maximum of the track, and a change of the value eases from the shown length. In the mode indeterminate, a short bar moves along the track to show that a task runs. start moves the bar with a timer, and stop ends the timer.

The parent of PATHNAME must exist, and PATHNAME must not. The class of the progress bar is TProgressbar, the name of its style.

Widget commands

CommandDescription
ttk::progressbar stepAdds an amount to the value.
ttk::progressbar startStarts a timer that calls step at each interval.
ttk::progressbar stopStops the timer of start.
ttk::progressbar stateGives the state flags of the widget, or turns flags on and off.
ttk::progressbar instateTests the state flags of the widget, and runs a script when they match.
ttk::progressbar identifyGives the name of the element of the widget at a point.
ttk::progressbar cgetGives the value of an option of the widget.
ttk::progressbar configureGives or sets the options of the widget.

Options

OptionTypeDefaultDatabase nameDescription
-classclass nameemptyThe class of the widget for the option database and for the bindings, set only at creation.
-cursorcursor nameemptycursorThe shape of the pointer over the widget.
-lengthscreen distance100lengthThe length of the track.
-maximumdouble100maximumThe value of a full bar.
-modemodedeterminatemodeWhether the bar shows an amount of work or only that a task runs.
-orientorientationhorizontalorientThe direction of the widget: horizontal or vertical.
-phaseinteger0phaseA counter for the animation of a theme.
-stylestyle nameemptystyleThe style of the widget, such as TProgressbar or a style of the script such as Accent.TProgressbar.
-takefocusboolean, empty, or scriptemptytakeFocusWhether the Tab key can move the focus to the widget.
-valuedouble0.0valueThe current value of the bar.
-variablevariable nameemptyvariableA global variable linked to the value of the bar.

-class CLASS

The class of the widget for the option database and for the bindings, set only at creation.

The class name replaces the class of the style, such as TProgressbar, in winfo class and in the bind tags of the widget. Give it in the call that makes the widget. A later configure of the option gives an error.

% ttk::progressbar .tpbcl -class Fancy
> winfo class .tpbcl
Fancy

% ttk::progressbar .tpbcl3
> winfo class .tpbcl3
TProgressbar
% ttk::progressbar .tpbcl2
> .tpbcl2 configure -class Other
attempt to change read-only option
-errorcode NONE

-cursor CURSOR

The shape of the pointer over the widget.

A cursor name of Tk, such as hand2 or xterm. An empty value uses the cursor of the parent.

% ttk::progressbar .tpbcu -cursor hand2
> .tpbcu cget -cursor
hand2

ztk stores each value of the option with no check.

-length DISTANCE

The length of the track.

The width of a horizontal bar, or the height of a vertical bar. A geometry manager can stretch the bar to another length.

ttk::progressbar with -value 40 and -length 60-length 60ttk::progressbar with -value 40 and -length 100-length 100ttk::progressbar with -value 40 and -length 200-length 200
Each with -value 40.
% ttk::progressbar .tpble -length 200
> winfo reqwidth .tpble
200
% ttk::progressbar .tpble2 -length x
bad screen distance "x"
-errorcode TK VALUE PIXELS

-maximum NUMBER

The value of a full bar.

The bar fills the fraction -value / -maximum of the track. A step past the maximum goes on from 0.

ttk::progressbar with -value 40 and -maximum 100-maximum 100ttk::progressbar with -value 40 and -maximum 50-maximum 50
Each with -value 40.
% ttk::progressbar .tpbma -maximum 10
> .tpbma step 25
> .tpbma cget -value
5.0
% ttk::progressbar .tpbma2 -maximum x
expected floating-point number but got "x"
-errorcode TCL VALUE NUMBER

-mode MODE

Whether the bar shows an amount of work or only that a task runs.

The mode sets how the bar draws the value.

ValueDescription
determinateThe bar fills the fraction -value / -maximum of the track.
indeterminateA short bar moves back and forth along the track, and -value sets its place.
ttk::progressbar with -value 40 and -mode determinate-mode determinatettk::progressbar with -value 40 and -mode indeterminate-mode indeterminate
Each with -value 40.
% ttk::progressbar .tpbmo -mode indeterminate
> .tpbmo cget -mode
indeterminate
% ttk::progressbar .tpbmo2 -mode bogus
bad mode "bogus": must be determinate or indeterminate
-errorcode TCL LOOKUP INDEX mode bogus

-orient ORIENT

The direction of the widget: horizontal or vertical.

A horizontal widget runs from left to right, and a vertical widget from top to bottom.

Values: horizontal, vertical.

ttk::progressbar with -value 40 and -orient horizontal-orient horizontalttk::progressbar with -value 40 and -orient vertical-orient vertical
Each with -value 40.
% ttk::progressbar .tpbor -orient vertical
> expr {[winfo reqheight .tpbor] > [winfo reqwidth .tpbor]}
1
% ttk::progressbar .tpbor2 -orient diagonal
bad orient "diagonal": must be horizontal or vertical
-errorcode TCL LOOKUP INDEX orient diagonal

-phase INTEGER

A counter for the animation of a theme.

Tk keeps the option for a theme that animates the bar. ztk stores the value, and step does not change it.

% ttk::progressbar .tpbph
> .tpbph step
> .tpbph cget -phase
0
% ttk::progressbar .tpbph2 -phase x
expected integer but got "x"
-errorcode TCL VALUE NUMBER

-style STYLE

The style of the widget, such as TProgressbar or a style of the script such as Accent.TProgressbar.

An empty value uses the style TProgressbar. A style name of the script ends with the name of the base style, such as Accent.TProgressbar, and ttk::style configure and ttk::style map give it its options. A style with no settings looks like its base style.

% ttk::style configure Accent.TProgressbar -foreground white
> ttk::progressbar .tpbsy -style Accent.TProgressbar
> .tpbsy cget -style
Accent.TProgressbar

ztk stores each value of the option with no check, as Tk 8.6.16 does at creation.

-takefocus VALUE

Whether the Tab key can move the focus to the widget.

1 puts the widget in the order of the Tab key, and 0 leaves it out. The default empty value uses the default rule of Tk, and this widget is not in the order of the Tab key with it. A script runs with the path of the widget appended, and its result is the answer.

% ttk::progressbar .tpbtf -takefocus 1
> .tpbtf cget -takefocus
1

ztk stores each value of the option with no check.

-value NUMBER

The current value of the bar.

In the mode determinate, the value sets the length of the bar. A value above -maximum draws a full bar and stays as it is.

ttk::progressbar with -value 0-value 0ttk::progressbar with -value 40-value 40ttk::progressbar with -value 100-value 100
% ttk::progressbar .tpbva -value 150
> .tpbva cget -value
150
% ttk::progressbar .tpbva2 -value x
expected floating-point number but got "x"
-errorcode TCL VALUE NUMBER

-variable VAR

A global variable linked to the value of the bar.

A change of the variable sets -value, and step sets the variable. The bar does not create the variable.

% ttk::progressbar .tpbvr -variable tpbvr
> set tpbvr 30
> .tpbvr step 5
> set tpbvr
35.0

Each name is a valid variable name.

Returns

PATHNAME.

Examples

% ttk::progressbar .load -maximum 10
> .load step 4
> .load cget -value
4.0

% winfo class [ttk::progressbar .busy -mode indeterminate]
TProgressbar

Errors

% ttk::progressbar .x -mode spin
bad mode "spin": must be determinate or indeterminate
-errorcode TCL LOOKUP INDEX mode spin

% ttk::progressbar .twice
> ttk::progressbar .twice
window name "twice" already exists in parent
-errorcode TK VALUE WINDOW EXISTS

# The parent .no does not exist.
% ttk::progressbar .no.p
bad window path name ".no"
-errorcode TK LOOKUP WINDOW .no

% ttk::progressbar
wrong # args: should be "ttk::progressbar pathName ?-option value ...?"
-errorcode TCL WRONGARGS

Differences from Tcl

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztk 1.0.0-beta.1

See also