beetlebug▾
/

ttk::scale

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

CommandDescription
ttk::scale getGives the value of the scale, or the value at a point.
ttk::scale setSets the value of the scale and runs its command.
ttk::scale coordsGives the pixel point of the center of the slider for a value.
ttk::scale stateGives the state flags of the widget, or turns flags on and off.
ttk::scale instateTests the state flags of the widget, and runs a script when they match.
ttk::scale identifyGives the name of the element of the widget at a point.
ttk::scale cgetGives the value of an option of the widget.
ttk::scale 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.
-commandscriptemptycommandA command prefix that runs after each change of the value, with the value appended.
-cursorcursor nameemptycursorThe shape of the pointer over the widget.
-fromdouble0fromThe number at the left or the top end of the scale.
-lengthscreen distance100lengthThe length of the long side of the widget.
-orientorientationhorizontalorientThe direction of the widget: horizontal or vertical.
-statestringnormalstateA state for compatibility with the classic widgets: normal or disabled.
-stylestyle nameemptystyleThe style of the widget, such as TScale or a style of the script such as Accent.TScale.
-takefocusboolean, empty, or scriptttk::takefocustakeFocusWhether the Tab key can move the focus to the widget.
-todouble1.0toThe number at the right or the bottom end of the scale.
-valuedouble0valueThe current value of the scale.
-variablevariable nameemptyvariableA 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.0

Each string is a valid prefix.

-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::scale .tsccu -cursor hand2
> .tsccu cget -cursor
hand2

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

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

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

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

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

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

ttk::scale with -to 100 and -value 0-value 0ttk::scale with -to 100 and -value 40-value 40ttk::scale with -to 100 and -value 100-value 100
Each with -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.0

Each name is a valid variable name.

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

StateDescription
activeThe pointer is over the slider. hover is the same flag in ztk.
pressedButton 1 is down on the slider.
focusThe scale has the keyboard focus.
disabledThe scale ignores the keyboard and the pointer, and the theme draws it grayed.
ttk::scale with -variable ::ref::level -to 100 and no state flagno state flagttk::scale with -variable ::ref::level -to 100 and state activestate activettk::scale with -variable ::ref::level -to 100 and state pressedstate pressedttk::scale with -variable ::ref::level -to 100 and state focusstate focus
Each with -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

Facts

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

See also