scale
Guide: Scale and scrollbar
Makes a scale: a slider that selects a number in a range.
scale PATHNAME ?OPTION VALUE ...?
Description
Makes a scale widget with the name PATHNAME and the options of the call, and makes the command PATHNAME for the widget commands below. The user drags the slider along a trough, or clicks the trough, to change the value. The value goes from -from to -to in steps of -resolution. -variable links a global variable to the value, and -command runs at each change of the user.
The parent of PATHNAME must exist, and PATHNAME must not. A scale is a Scale in CSS and for the option database, and ztk::class gives it a style class for a stylesheet. The default -orient is vertical.
Widget commands
| Command | Description |
|---|---|
scale coords | Gives the point in the scale of a value. |
scale get | Gives the value of the scale, or the value at a point. |
scale identify | Gives the part of the scale at a point. |
scale set | Sets the value of the scale. |
scale cget | Gives the value of an option of the scale. |
scale configure | Gives or sets the options of the scale. |
Options
| Option | Type | Default | Database name | Description |
|---|---|---|---|---|
-activebackground | color | #ececec | activeBackground | The background color of the active state, in the look of Tk on X11. |
-background | color | #d9d9d9 | background | The background color of the scale. |
-bigincrement | number | 0 | bigIncrement | The size of a large step of the keyboard. |
-borderwidth | screen distance | 0 | borderWidth | The width of the border of the scale. |
-command | script | empty | command | A command prefix that the scale calls when the user changes the value. |
-cursor | cursor name | empty | cursor | The shape of the pointer over the scale. |
-digits | integer | 0 | digits | The count of significant digits of the value. |
-font | font | TkDefaultFont | font | The font of the label, the value, and the tick marks. |
-foreground | color | #000000 | foreground | The color of the label, the value, and the tick marks. |
-from | number | 0 | from | The value at the left or top end of the scale. |
-highlightbackground | color | #d9d9d9 | highlightBackground | The color of the focus ring while the scale has no focus, in the look of Tk on X11. |
-highlightcolor | color | #000000 | highlightColor | The color of the focus ring while the scale has the focus, in the look of Tk on X11. |
-highlightthickness | screen distance | 1 | highlightThickness | The width of the focus ring, in the look of Tk on X11. |
-label | string | empty | label | A text that the scale shows next to the slider. |
-length | screen distance | 100 | length | The length of the long side of the scale. |
-orient | orient | vertical | orient | The direction of the scale: horizontal or vertical. |
-relief | relief | flat | relief | The 3-D look of the border. |
-repeatdelay | integer | 300 | repeatDelay | The time in milliseconds before a held button starts to repeat. |
-repeatinterval | integer | 100 | repeatInterval | The time in milliseconds between two repeats of a held button. |
-resolution | number | 1 | resolution | The step of the value. |
-showvalue | boolean | 1 | showValue | Whether the scale shows its value next to the slider. |
-sliderlength | screen distance | 30 | sliderLength | The length of the slider along the scale. |
-sliderrelief | relief | raised | sliderRelief | The relief of the slider. |
-state | state | normal | state | The state of the scale: normal, active, or disabled. |
-takefocus | string | empty | takeFocus | Whether the Tab key can move the focus to the scale. |
-tickinterval | number | 0 | tickInterval | The distance between two tick values. |
-to | number | 100 | to | The value at the right or bottom end of the scale. |
-troughcolor | color | #b3b3b3 | troughColor | The color of the trough, in the look of Tk on X11. |
-variable | variable name | empty | variable | A global variable that holds the value of the scale. |
-width | screen distance | 15 | width | The width of the short side of the scale. |
-activebackground COLOR
The background color of the active state, in the look of Tk on X11.
The color of the slider while the pointer is over it. A color is a name such as red, or #RGB, #RRGGBB, or #RRRRGGGGBBBB.
% scale .activebackground -activebackground {#336699}
> .activebackground cget -activebackground
#336699% scale .activebackground2 -activebackground nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor-background COLOR
The background color of the scale.
The color behind the content. -bg is the same option. A color is a name such as red, or #RGB, #RRGGBB, or #RRRRGGGGBBBB.

-background {#fde68a}
-background {#bfdbfe}-variable ::ref::level -to 100.% scale .background -background {#336699}
> .background cget -background
#336699% scale .background2 -background nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor-bigincrement NUMBER
The size of a large step of the keyboard.
Control with an arrow key moves the value by this step. 0 makes the step a tenth of the range.
% scale .bigincrement -bigincrement 2.5
> .bigincrement cget -bigincrement
2.5% scale .bigincrement2 -bigincrement x
expected floating-point number but got "x"
-errorcode TCL VALUE NUMBER-borderwidth DISTANCE
The width of the border of the scale.
The width of the border around the scale. -bd is the same option. A distance is a count of pixels, or a number with c, i, m, or p for centimeters, inches, millimeters, or points.

-borderwidth 0
-borderwidth 1
-borderwidth 4-variable ::ref::level -to 100 -relief solid.% scale .borderwidth -borderwidth 4
> .borderwidth cget -borderwidth
4% scale .borderwidth2 -borderwidth x
bad screen distance "x"
-errorcode TK VALUE PIXELS-command PREFIX
A command prefix that the scale calls when the user changes the value.
The scale adds the new value as one more word and runs the command at the global level, at once after the change. A change of set or of the variable runs no command.
% scale .command -command {set ::done 1}
> .command cget -command
set ::done 1ztk stores each prefix with no check.
-cursor CURSOR
The shape of the pointer over the scale.
Each value side by side: the contact sheet of the cursors
A cursor name of Tk, such as hand2 or xterm. A value that starts with @ names a file. An empty value uses the cursor of the parent.
% scale .cursor -cursor hand2
> .cursor cget -cursor
hand2% scale .cursor2 -cursor nocursor
bad cursor spec "nocursor"
-errorcode TK VALUE CURSOR-digits N
The count of significant digits of the value.
The scale rounds its value to this count of digits for get, the variable, and the text of the value. 0 or less uses the fewest digits that show each step of -resolution.
% scale .digits -digits 5
> .digits cget -digits
5% scale .digits2 -digits x
expected integer but got "x"
-errorcode TCL VALUE NUMBER-font FONT
The font of the label, the value, and the tick marks.
A font name, such as TkDefaultFont, or a font description, such as {Helvetica 12 bold}. A family that does not exist falls back to a font of the system.

-font TkDefaultFont
-font {Helvetica 16 bold}-variable ::ref::level -to 100.% scale .font -font {Helvetica 12 bold}
> .font cget -font
Helvetica 12 bold% scale .font2 -font {Helvetica big}
expected integer but got "big"
-errorcode TCL VALUE NUMBER-foreground COLOR
The color of the label, the value, and the tick marks.
-fg is the same option. A color is a name such as red, or #RGB, #RRGGBB, or #RRRRGGGGBBBB.
% scale .foreground -foreground {#336699}
> .foreground cget -foreground
#336699% scale .foreground2 -foreground nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor-from NUMBER
The value at the left or top end of the scale.
The value of the slider at the start of the scale. -from can be larger than -to, and the scale then counts down.
% scale .from -from 10 -to 0
> .from set 3
> .from get
3% scale .from2 -from x
expected floating-point number but got "x"
-errorcode TCL VALUE NUMBER-highlightbackground COLOR
The color of the focus ring while the scale has no focus, in the look of Tk on X11.
The color of the highlight ring of -highlightthickness while the scale does not have the focus. ztk stores the value with no effect.
% scale .highlightbackground -highlightbackground {#336699}
> .highlightbackground cget -highlightbackground
#336699% scale .highlightbackground2 -highlightbackground nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor-highlightcolor COLOR
The color of the focus ring while the scale has the focus, in the look of Tk on X11.
The color of the highlight ring of -highlightthickness while the scale has the focus. ztk stores the value with no effect.
% scale .highlightcolor -highlightcolor {#336699}
> .highlightcolor cget -highlightcolor
#336699% scale .highlightcolor2 -highlightcolor nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor-highlightthickness DISTANCE
The width of the focus ring, in the look of Tk on X11.
The width of the ring around the scale that shows the focus. The modern theme draws the focus with the stylesheet.
% scale .highlightthickness -highlightthickness 4
> .highlightthickness cget -highlightthickness
4% scale .highlightthickness2 -highlightthickness x
bad screen distance "x"
-errorcode TK VALUE PIXELS-label TEXT
A text that the scale shows next to the slider.
The scale shows the label at its top left side. An empty value shows no label.

-label {}
-label Volume-variable ::ref::level -to 100 -orient horizontal.% scale .label -label Size
> .label cget -label
SizeEach string is a valid label.
-length DISTANCE
The length of the long side of the scale.
The scale asks for this length along its -orient direction. A distance is a count of pixels, or a number with c, i, m, or p for centimeters, inches, millimeters, or points.

-length 60
-length 100
-length 200-variable ::ref::level -to 100 -orient horizontal.% scale .length -length 4
> .length cget -length
4% scale .length2 -length x
bad screen distance "x"
-errorcode TK VALUE PIXELS-orient WORD
The direction of the scale: horizontal or vertical.
The scale lies along this direction.
Values: horizontal, vertical.

-orient vertical
-orient horizontal-variable ::ref::level -to 100.% scale .orient -orient horizontal
> .orient cget -orient
horizontal% scale .orient2 -orient bogus
bad orient "bogus": must be horizontal or vertical
-errorcode TCL LOOKUP INDEX orient bogus-relief RELIEF
The 3-D look of the border.
Each value side by side: the contact sheet of the reliefs
The style of the border: raised and sunken look 3-D, and groove and ridge are lines. The theme draws the border, and the CSS of the theme can give a relief its own look with border-style.
Values: flat, groove, raised, ridge, solid, sunken.
% scale .relief -relief groove
> .relief cget -relief
groove% scale .relief2 -relief bumpy
bad relief "bumpy": must be flat, groove, raised, ridge, solid, or sunken
-errorcode TCL LOOKUP INDEX relief bumpy-repeatdelay N
The time in milliseconds before a held button starts to repeat.
In Tk, a press that is held on the trough repeats its step after this delay. ztk stores the value with no effect: a press moves one step.
% scale .repeatdelay -repeatdelay 5
> .repeatdelay cget -repeatdelay
5% scale .repeatdelay2 -repeatdelay x
expected integer but got "x"
-errorcode TCL VALUE NUMBER-repeatinterval N
The time in milliseconds between two repeats of a held button.
In Tk, a held press repeats its step at this interval. ztk stores the value with no effect.
% scale .repeatinterval -repeatinterval 5
> .repeatinterval cget -repeatinterval
5% scale .repeatinterval2 -repeatinterval x
expected integer but got "x"
-errorcode TCL VALUE NUMBER-resolution NUMBER
The step of the value.
The scale rounds each value to a multiple of this step. 0 or less turns off the rounding.
% scale .resolution -to 100 -resolution 5
> .resolution set 42
> .resolution get
40% scale .resolution2 -resolution x
expected floating-point number but got "x"
-errorcode TCL VALUE NUMBER-showvalue BOOLEAN
Whether the scale shows its value next to the slider.
With a true value, the scale shows the current value as text.

-showvalue 1
-showvalue 0-variable ::ref::level -to 100 -orient horizontal.% scale .showvalue -showvalue 0
> .showvalue cget -showvalue
0% scale .showvalue2 -showvalue maybe
expected boolean value but got "maybe"
-errorcode TCL VALUE NUMBER-sliderlength DISTANCE
The length of the slider along the scale.
In Tk, the slider has this size along the trough. ztk stores the value with no effect: the theme gives the size of the slider.
% scale .sliderlength -sliderlength 4
> .sliderlength cget -sliderlength
4% scale .sliderlength2 -sliderlength x
bad screen distance "x"
-errorcode TK VALUE PIXELS-sliderrelief RELIEF
The relief of the slider.
In Tk, the slider has this 3-D look. ztk stores the value with no effect.
Values: flat, groove, raised, ridge, solid, sunken.
% scale .sliderrelief -sliderrelief groove
> .sliderrelief cget -sliderrelief
groove% scale .sliderrelief2 -sliderrelief bumpy
bad relief "bumpy": must be flat, groove, raised, ridge, solid, or sunken
-errorcode TCL LOOKUP INDEX relief bumpy-state STATE
The state of the scale: normal, active, or disabled.
disabled blocks the changes of the user and of set. active shows the slider with -activebackground.
Values: active, disabled, normal.
# A disabled scale keeps its value.
% scale .state -state disabled
> .state set 5
> .state get
0% scale .state2 -state busy
bad state "busy": must be active, disabled, or normal
-errorcode TCL LOOKUP INDEX state busy-takefocus TEXT
Whether the Tab key can move the focus to the scale.
1 puts the scale in the order of the Tab key, and 0 leaves it out. An empty value uses the default rule of Tk for the widget. In Tk the value can also be a script, and its result is the answer. ztk stores each value with no check.
% scale .takefocus -takefocus 1
> .takefocus cget -takefocus
1ztk stores each value of the option with no check.
-tickinterval NUMBER
The distance between two tick values.
The scale shows the values at each multiple of this distance along the trough. 0 shows no tick values.

-tickinterval 0
-tickinterval 25
-tickinterval 50-variable ::ref::level -to 100 -orient horizontal -length 200.% scale .tickinterval -tickinterval 2.5
> .tickinterval cget -tickinterval
2.5% scale .tickinterval2 -tickinterval x
expected floating-point number but got "x"
-errorcode TCL VALUE NUMBER-to NUMBER
The value at the right or bottom end of the scale.
The value of the slider at the end of the scale. set limits a value to the range between -from and -to.
% scale .to -to 50
> .to set 80
> .to get
50% scale .to2 -to x
expected floating-point number but got "x"
-errorcode TCL VALUE NUMBER-troughcolor COLOR
The color of the trough, in the look of Tk on X11.
The color of the long area that the slider moves in. ztk stores the value with no effect.
% scale .troughcolor -troughcolor {#336699}
> .troughcolor cget -troughcolor
#336699% scale .troughcolor2 -troughcolor nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor-variable VAR
A global variable that holds the value of the scale.
The scale sets the variable when its value changes, and a change of the variable moves the slider. When the variable has no value, the scale sets it to its value.
% scale .variable -variable level
> .variable set 20
> set level
20
% set volume 30
> scale .variable2 -variable volume
> .variable2 get
30Each name is a valid variable name.
-width DISTANCE
The width of the short side of the scale.
The size of the trough across the -orient direction. A distance is a count of pixels, or a number with c, i, m, or p for centimeters, inches, millimeters, or points.
% scale .width -width 4
> .width cget -width
4% scale .width2 -width x
bad screen distance "x"
-errorcode TK VALUE PIXELSBindings
| 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 of -resolution 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 of -resolution toward -from. Up does the same. |
<Key-Right> | Moves the value one step of -resolution toward -to. Down does the same. |
<Control-Key-Left> | Moves the value one big step toward -from: -bigincrement, or a tenth of the range when it is 0. 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. |
Returns
PATHNAME.
Examples
% scale .volume -from 0 -to 10 -orient horizontal
> .volume set 7
> .volume get
7
# The scale rounds 110 to a multiple of 25.
% scale .zoom -to 200 -resolution 25 -variable zoom
> .zoom set 110
> set zoom
100
% winfo class [scale .go]
Scale
Errors
% scale .x -foo 1
unknown option "-foo"
-errorcode TK LOOKUP OPTION -foo
% scale .twice
> scale .twice
window name "twice" already exists in parent
-errorcode TK VALUE WINDOW EXISTS
# The parent .no does not exist.
% scale .no.b
bad window path name ".no"
-errorcode TK LOOKUP WINDOW .no
% scale
wrong # args: should be "scale pathName ?-option value ...?"
-errorcode TCL WRONGARGS
Differences from Tcl
-toand-tickintervalkeep a value that is not a multiple of-resolution:scale .s -to 2.5gives 2.5 forcget -to. Tk 8.6.16 rounds the value, and gives 3.0.- A scale runs
-commandat once after a change of the user. Tk 8.6.16 runs it as an idle callback. - A press on the trough moves one step. Holding the button does not repeat, so
-repeatdelayand-repeatintervalhave no effect. - An error of a wrong count of arguments of a widget command, or of a bad number in
set, has the-errorcodeNONE. Tk 8.6.16 givesTCL WRONGARGSorTCL VALUE NUMBER. -sliderlength,-sliderrelief,-troughcolor,-highlightbackground, and-highlightcolorare stored with no effect. The theme gives the look of the trough and the slider.
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztk 1.0.0-beta.1