beetlebug▾
/

scale

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

CommandDescription
scale coordsGives the point in the scale of a value.
scale getGives the value of the scale, or the value at a point.
scale identifyGives the part of the scale at a point.
scale setSets the value of the scale.
scale cgetGives the value of an option of the scale.
scale configureGives or sets the options of the scale.

Options

OptionTypeDefaultDatabase nameDescription
-activebackgroundcolor#ecececactiveBackgroundThe background color of the active state, in the look of Tk on X11.
-backgroundcolor#d9d9d9backgroundThe background color of the scale.
-bigincrementnumber0bigIncrementThe size of a large step of the keyboard.
-borderwidthscreen distance0borderWidthThe width of the border of the scale.
-commandscriptemptycommandA command prefix that the scale calls when the user changes the value.
-cursorcursor nameemptycursorThe shape of the pointer over the scale.
-digitsinteger0digitsThe count of significant digits of the value.
-fontfontTkDefaultFontfontThe font of the label, the value, and the tick marks.
-foregroundcolor#000000foregroundThe color of the label, the value, and the tick marks.
-fromnumber0fromThe value at the left or top end of the scale.
-highlightbackgroundcolor#d9d9d9highlightBackgroundThe color of the focus ring while the scale has no focus, in the look of Tk on X11.
-highlightcolorcolor#000000highlightColorThe color of the focus ring while the scale has the focus, in the look of Tk on X11.
-highlightthicknessscreen distance1highlightThicknessThe width of the focus ring, in the look of Tk on X11.
-labelstringemptylabelA text that the scale shows next to the slider.
-lengthscreen distance100lengthThe length of the long side of the scale.
-orientorientverticalorientThe direction of the scale: horizontal or vertical.
-reliefreliefflatreliefThe 3-D look of the border.
-repeatdelayinteger300repeatDelayThe time in milliseconds before a held button starts to repeat.
-repeatintervalinteger100repeatIntervalThe time in milliseconds between two repeats of a held button.
-resolutionnumber1resolutionThe step of the value.
-showvalueboolean1showValueWhether the scale shows its value next to the slider.
-sliderlengthscreen distance30sliderLengthThe length of the slider along the scale.
-sliderreliefreliefraisedsliderReliefThe relief of the slider.
-statestatenormalstateThe state of the scale: normal, active, or disabled.
-takefocusstringemptytakeFocusWhether the Tab key can move the focus to the scale.
-tickintervalnumber0tickIntervalThe distance between two tick values.
-tonumber100toThe value at the right or bottom end of the scale.
-troughcolorcolor#b3b3b3troughColorThe color of the trough, in the look of Tk on X11.
-variablevariable nameemptyvariableA global variable that holds the value of the scale.
-widthscreen distance15widthThe 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.

scale with -variable ::ref::level -to 100 and -background {#fde68a}-background {#fde68a}scale with -variable ::ref::level -to 100 and -background {#bfdbfe}-background {#bfdbfe}
Each with -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.

scale with -variable ::ref::level -to 100 -relief solid and -borderwidth 0-borderwidth 0scale with -variable ::ref::level -to 100 -relief solid and -borderwidth 1-borderwidth 1scale with -variable ::ref::level -to 100 -relief solid and -borderwidth 4-borderwidth 4
Each with -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 1

ztk stores each prefix with no check.

-cursor CURSOR

The shape of the pointer over the scale.

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.

scale with -variable ::ref::level -to 100 and -font TkDefaultFont-font TkDefaultFontscale with -variable ::ref::level -to 100 and -font {Helvetica 16 bold}-font {Helvetica 16 bold}
Each with -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.

scale with -variable ::ref::level -to 100 -orient horizontal and -label {}-label {}scale with -variable ::ref::level -to 100 -orient horizontal and -label Volume-label Volume
Each with -variable ::ref::level -to 100 -orient horizontal.
% scale .label -label Size
> .label cget -label
Size

Each 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.

scale with -variable ::ref::level -to 100 -orient horizontal and -length 60-length 60scale with -variable ::ref::level -to 100 -orient horizontal and -length 100-length 100scale with -variable ::ref::level -to 100 -orient horizontal and -length 200-length 200
Each with -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.

scale with -variable ::ref::level -to 100 and -orient vertical-orient verticalscale with -variable ::ref::level -to 100 and -orient horizontal-orient horizontal
Each with -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.

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.

scale with -variable ::ref::level -to 100 -orient horizontal and -showvalue 1-showvalue 1scale with -variable ::ref::level -to 100 -orient horizontal and -showvalue 0-showvalue 0
Each with -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
1

ztk 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.

scale with -variable ::ref::level -to 100 -orient horizontal -length 200 and -tickinterval 0-tickinterval 0scale with -variable ::ref::level -to 100 -orient horizontal -length 200 and -tickinterval 25-tickinterval 25scale with -variable ::ref::level -to 100 -orient horizontal -length 200 and -tickinterval 50-tickinterval 50
Each with -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
30

Each 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 PIXELS

Bindings

EventDescription
<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

Facts

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

See also