beetlebug▾
/

ttk::scrollbar

Makes a themed scrollbar: a bar that shows and moves the visible part of another widget.

ttk::scrollbar PATHNAME ?OPTION VALUE ...?

Description

Makes a themed scrollbar with the name PATHNAME and the options of the call, and makes the command PATHNAME for the widget commands below. The scrollbar has a trough and a thumb. The size and the place of the thumb show the visible part of a widget that scrolls, such as a listbox, a text, or a ttk::treeview.

The link has two sides. The -yscrollcommand or -xscrollcommand of the other widget calls set of the scrollbar. A drag of the thumb, or a click on the trough, calls the -command of the scrollbar with moveto or scroll, and the command is the yview or xview of the other widget.

The parent of PATHNAME must exist, and PATHNAME must not. The class of the scrollbar is TScrollbar, the name of its style.

Widget commands

CommandDescription
ttk::scrollbar setSets the visible part that the thumb shows.
ttk::scrollbar getGives the two fractions of the last set.
ttk::scrollbar deltaGives the change of the fraction for a move of the thumb by some pixels.
ttk::scrollbar fractionGives the fraction of the trough at a pixel point.
ttk::scrollbar stateGives the state flags of the widget, or turns flags on and off.
ttk::scrollbar instateTests the state flags of the widget, and runs a script when they match.
ttk::scrollbar identifyGives the name of the element of the widget at a point.
ttk::scrollbar cgetGives the value of an option of the widget.
ttk::scrollbar 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.
-commandscriptemptycommandThe command prefix that the scrollbar calls to scroll the other widget.
-cursorcursor nameemptycursorThe shape of the pointer over the widget.
-orientorientationverticalorientThe direction of the scrollbar: vertical or horizontal.
-stylestyle nameemptystyleThe style of the widget, such as TScrollbar or a style of the script such as Accent.TScrollbar.
-takefocusboolean, empty, or scriptemptytakeFocusWhether the Tab key can move the focus to the widget.

-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 TScrollbar, 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::scrollbar .tsrcl -class Fancy
> winfo class .tsrcl
Fancy

% ttk::scrollbar .tsrcl3
> winfo class .tsrcl3
TScrollbar
% ttk::scrollbar .tsrcl2
> .tsrcl2 configure -class Other
attempt to change read-only option
-errorcode NONE

-command PREFIX

The command prefix that the scrollbar calls to scroll the other widget.

A drag of the thumb calls the prefix with moveto FRACTION appended. A click on the trough calls it with scroll COUNT pages appended, and the arrows of the theme classic with scroll COUNT units. The prefix is often {WIDGET yview} or {WIDGET xview}.

% ttk::scrollbar .tsrcm -command {.list yview}
> .tsrcm cget -command
.list yview

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::scrollbar .tsrcu -cursor hand2
> .tsrcu cget -cursor
hand2

ztk stores each value of the option with no check.

-orient ORIENT

The direction of the scrollbar: vertical or horizontal.

A vertical scrollbar scrolls up and down, and a horizontal scrollbar scrolls left and right.

Values: horizontal, vertical.

ttk::scrollbar with -orient vertical-orient verticalttk::scrollbar with -orient horizontal-orient horizontal
% ttk::scrollbar .tsror -orient horizontal
> .tsror cget -orient
horizontal
% ttk::scrollbar .tsror2 -orient diagonal
bad orient "diagonal": must be horizontal or vertical
-errorcode TCL LOOKUP INDEX orient diagonal

-style STYLE

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

An empty value uses the style TScrollbar. A style name of the script ends with the name of the base style, such as Accent.TScrollbar, 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.TScrollbar -foreground white
> ttk::scrollbar .tsrsy -style Accent.TScrollbar
> .tsrsy cget -style
Accent.TScrollbar

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::scrollbar .tsrtf -takefocus 1
> .tsrtf cget -takefocus
1

ztk stores each value of the option with no check.

Bindings

EventDescription
<Button-1>A press on the thumb starts a drag. A press on an arrow scrolls one unit, and a press on the trough scrolls one page, toward the press.
<B1-Motion>During a drag, the thumb follows the pointer, and the scrollbar runs -command with moveto.
<ButtonRelease-1>Ends the drag.
<Button-2>Moves the center of the thumb to the pointer.
<MouseWheel>Scrolls a vertical scrollbar, 4 units for each step of the wheel. With Shift, the wheel scrolls a horizontal scrollbar.
<Key-Up>Scrolls a vertical scrollbar one unit up. Down scrolls one unit down, and Left and Right do the same for a horizontal scrollbar.
<Control-Key-Up>Scrolls a vertical scrollbar one page up. Control-Down, Control-Left, and Control-Right scroll one page.
<Key-Prior>Scrolls one page back. Next scrolls one page forward.
<Key-Home>Runs -command with moveto 0.
<Key-End>Runs -command with moveto 1.

Returns

PATHNAME.

Examples

% listbox .items -yscrollcommand {.sb set}
> ttk::scrollbar .sb -command {.items yview}
> for {set i 0} {$i < 100} {incr i} {.items insert end "Item $i"}
> pack .items .sb -side left -fill y
> update
> lindex [.sb get] 0
0.0

% winfo class [ttk::scrollbar .vs]
TScrollbar

Errors

# The style sets the width of a themed scrollbar.
% ttk::scrollbar .x -width 10
unknown option "-width"
-errorcode TK LOOKUP OPTION -width

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

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

% ttk::scrollbar
wrong # args: should be "ttk::scrollbar 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