ttk::scale
Guide: Themed widgets (ttk)
Makes a themed scale: a slider that the user drags to pick a number in a range.
ttk::scale PATHNAME ?OPTION VALUE ...?
Description
Makes a themed scale with the name PATHNAME and the options of the call, and makes the command PATHNAME for the widget commands below. The scale has a trough and a slider. A drag of the slider, a click on the trough, or set changes the value in the range of -from and -to, and then runs -command.
The value is a floating-point number. -variable links it to a global variable. The parent of PATHNAME must exist, and PATHNAME must not. The class of the scale is TScale, the name of its style.
Widget commands
| Command | Description |
|---|---|
ttk::scale get | Gives the value of the scale, or the value at a point. |
ttk::scale set | Sets the value of the scale and runs its command. |
ttk::scale coords | Gives the pixel point of the center of the slider for a value. |
ttk::scale state | Gives the state flags of the widget, or turns flags on and off. |
ttk::scale instate | Tests the state flags of the widget, and runs a script when they match. |
ttk::scale identify | Gives the name of the element of the widget at a point. |
ttk::scale cget | Gives the value of an option of the widget. |
ttk::scale configure | Gives or sets the options of the widget. |
Options
| Option | Type | Default | Database name | Description |
|---|---|---|---|---|
-class | class name | empty | The class of the widget for the option database and for the bindings, set only at creation. | |
-command | script | empty | command | A command prefix that runs after each change of the value, with the value appended. |
-cursor | cursor name | empty | cursor | The shape of the pointer over the widget. |
-from | double | 0 | from | The number at the left or the top end of the scale. |
-length | screen distance | 100 | length | The length of the long side of the widget. |
-orient | orientation | horizontal | orient | The direction of the widget: horizontal or vertical. |
-state | string | normal | state | A state for compatibility with the classic widgets: normal or disabled. |
-style | style name | empty | style | The style of the widget, such as TScale or a style of the script such as Accent.TScale. |
-takefocus | boolean, empty, or script | ttk::takefocus | takeFocus | Whether the Tab key can move the focus to the widget. |
-to | double | 1.0 | to | The number at the right or the bottom end of the scale. |
-value | double | 0 | value | The current value of the scale. |
-variable | variable name | empty | variable | A global variable linked to the value of the scale. |
-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 TScale, 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::scale .tsccl -class Fancy
> winfo class .tsccl
Fancy
% ttk::scale .tsccl3
> winfo class .tsccl3
TScale% ttk::scale .tsccl2
> .tsccl2 configure -class Other
attempt to change read-only option
-errorcode NONE-command PREFIX
A command prefix that runs after each change of the value, with the value appended.
The prefix runs at the global level with the new value appended, after a drag, a click, or set. A configure -value and a change of -variable run no command.
% ttk::scale .tsccm -from 0 -to 10 -command {lappend ::tsclog}
> .tsccm set 3
> set ::tsclog
3.0Each string is a valid prefix.
-cursor CURSOR
The shape of the pointer over the widget.
Each value side by side: the contact sheet of the cursors
A cursor name of Tk, such as hand2 or xterm. An empty value uses the cursor of the parent.
% ttk::scale .tsccu -cursor hand2
> .tsccu cget -cursor
hand2ztk stores each value of the option with no check.
-from NUMBER
The number at the left or the top end of the scale.
set keeps the value between -from and -to. -from can be larger than -to, for a scale that counts down.
% ttk::scale .tscfr -from 0 -to 100
> .tscfr set 50
> .tscfr set -5
> .tscfr get
0.0% ttk::scale .tscfr2 -from x
expected floating-point number but got "x"
-errorcode TCL VALUE NUMBER-length DISTANCE
The length of the long side of the widget.
The width of a horizontal widget, or the height of a vertical widget. A geometry manager can stretch the widget to another length.

-length 60
-length 100
-length 200-variable ::ref::level -to 100.% ttk::scale .tscle -length 100
> ttk::scale .tscle200 -length 200
> expr {[winfo reqwidth .tscle200] - [winfo reqwidth .tscle]}
100% ttk::scale .tscle2 -length x
bad screen distance "x"
-errorcode TK VALUE PIXELS-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.

-orient horizontal
-orient vertical-variable ::ref::level -to 100.% ttk::scale .tscor -orient vertical
> expr {[winfo reqheight .tscor] > [winfo reqwidth .tscor]}
1% ttk::scale .tscor2 -orient diagonal
bad orient "diagonal": must be horizontal or vertical
-errorcode TCL LOOKUP INDEX orient diagonal-state STATE
A state for compatibility with the classic widgets: normal or disabled.
disabled sets the state flag disabled: the user cannot move the slider, and set makes no change. normal clears the flag. ztk stores each other value with no check.
% ttk::scale .tscst -state disabled
> .tscst set 0.5
> .tscst get
0ztk stores each value of the option with no check, as Tk 8.6.16 does.
-style STYLE
The style of the widget, such as TScale or a style of the script such as Accent.TScale.
An empty value uses the style TScale. A style name of the script ends with the name of the base style, such as Accent.TScale, 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.TScale -foreground white
> ttk::scale .tscsy -style Accent.TScale
> .tscsy cget -style
Accent.TScaleztk 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. An empty value uses the default rule of Tk. A script, such as the default ttk::takefocus, runs with the path of the widget appended, and its result is the answer. ttk::takefocus gives 1 when the widget is not disabled and is viewable.
% ttk::scale .tsctf -takefocus 0
> .tsctf cget -takefocus
0ztk stores each value of the option with no check.
-to NUMBER
The number at the right or the bottom end of the scale.
set keeps the value between -from and -to.
% ttk::scale .tscto -from 0 -to 100
> .tscto set 200
> .tscto get
100.0% ttk::scale .tscto2 -to x
expected floating-point number but got "x"
-errorcode TCL VALUE NUMBER-value NUMBER
The current value of the scale.
A configure of the value moves the slider and runs no -command. With -variable, the variable also gets the value.

-value 0
-value 40
-value 100-to 100.% ttk::scale .tscva -from 0 -to 100 -value 30
> .tscva get
30% ttk::scale .tscva2 -value x
expected floating-point number but got "x"
-errorcode TCL VALUE NUMBER-variable VAR
A global variable linked to the value of the scale.
A change of the value sets the variable, and a change of the variable moves the slider. The scale does not create the variable before the first change of the value.
% ttk::scale .tscvr -from 0 -to 10 -variable tscvr
> .tscvr set 2
> set tscvr
2.0Each name is a valid variable name.
Bindings
| Event | Description |
|---|---|
<Button-1> | A press on the slider starts a drag, and gives the widget the focus. A press on the trough moves the value one step toward the pointer. |
<B1-Motion> | During a drag, the slider follows the pointer, and the value changes. |
<ButtonRelease-1> | Ends the drag. |
<Control-Button-1> | A press on the trough sets the value to the end of the scale on the side of the pointer: -from or -to. |
<Button-2> | Sets the value at the pointer. |
<Key-Left> | Moves the value one step toward -from. Up does the same. |
<Key-Right> | Moves the value one step toward -to. Down does the same. |
<Control-Key-Left> | Moves the value one big step toward -from: a tenth of the range. Control-Up does the same. |
<Control-Key-Right> | Moves the value one big step toward -to. Control-Down does the same. |
<Key-Home> | Sets the value to -from. |
<Key-End> | Sets the value to -to. |
States
| State | Description |
|---|---|
active | The pointer is over the slider. hover is the same flag in ztk. |
pressed | Button 1 is down on the slider. |
focus | The scale has the keyboard focus. |
disabled | The scale ignores the keyboard and the pointer, and the theme draws it grayed. |

no state flag
state active
state pressed
state focus-variable ::ref::level -to 100.Returns
PATHNAME.
Examples
% ttk::scale .volume -from 0 -to 100
> .volume set 40
> .volume get
40.0
% winfo class [ttk::scale .speed]
TScale
Errors
# A themed scale has no `-resolution`. Round the value in `-command`.
% ttk::scale .x -resolution 1
unknown option "-resolution"
-errorcode TK LOOKUP OPTION -resolution
% ttk::scale .twice
> ttk::scale .twice
window name "twice" already exists in parent
-errorcode TK VALUE WINDOW EXISTS
# The parent .no does not exist.
% ttk::scale .no.s
bad window path name ".no"
-errorcode TK LOOKUP WINDOW .no
% ttk::scale
wrong # args: should be "ttk::scale pathName ?-option value ...?"
-errorcode TCL WRONGARGS
Differences from Tcl
-cursoraccepts each value with no check. Tk 8.6.16 gives an error for a cursor name that does not exist.- The errors of
state,instate,identify, and of an unknown widget command have the error codeNONE. Tk 8.6.16 gives a code such asTTK VALUE STATEorTCL LOOKUP INDEX. The error of-underlinehas the codeTCL VALUE NUMBER, where Tk 8.6.16 givesTCL VALUE INTEGER. - The states
activeandhoverare one flag, sostate activeturns on both. setgives an empty string. Tk 8.6.16 gives the result of-command.- The errors of
getandsethave the error codeNONE. Tk 8.6.16 givesTCL WRONGARGSorTCL VALUE NUMBER. - After a change of the variable,
getgives the string of the variable, such as7. Tk 8.6.16 gives a floating-point number, such as7.0. - The requested length is 4 pixels more than
-length, and the pixels ofcoordsandget X Ydiffer from Tk 8.6.16 by the size of the slider of the theme.
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztk 1.0.0-beta.1