beetlebug▾
/

scrollbar

Makes a scrollbar: a bar with a slider that scrolls the view of another widget.

scrollbar PATHNAME ?OPTION VALUE ...?

Description

Makes a scrollbar widget with the name PATHNAME and the options of the call, and makes the command PATHNAME for the widget commands below. A scrollbar and a scrollable widget, such as a listbox or a text, work as a pair:

The parent of PATHNAME must exist, and PATHNAME must not. A scrollbar is a Scrollbar in CSS and for the option database, and ztk::class gives it a style class for a stylesheet. The default -orient is vertical.

The modern scrollbar has a trough and a slider, and no arrows. The theme classic has the look of Tk on X11.

Widget commands

CommandDescription
scrollbar activateGives or sets the active element of the scrollbar.
scrollbar deltaGives the change of the fraction for a move of the slider by a distance.
scrollbar fractionGives the fraction of the trough at a point.
scrollbar getGives the values of the last set.
scrollbar identifyGives the element of the scrollbar at a point.
scrollbar setSets the visible part of the content, which the slider shows.
scrollbar cgetGives the value of an option of the scrollbar.
scrollbar configureGives or sets the options of the scrollbar.

Options

OptionTypeDefaultDatabase nameDescription
-activebackgroundcolor#ecececactiveBackgroundThe background color of the active state, in the look of Tk on X11.
-activereliefreliefraisedactiveReliefThe relief of the active element.
-backgroundcolor#d9d9d9backgroundThe background color of the scrollbar.
-borderwidthscreen distance1borderWidthThe width of the border of the scrollbar.
-commandscriptemptycommandThe command prefix that the scrollbar calls to scroll its widget.
-cursorcursor nameemptycursorThe shape of the pointer over the scrollbar.
-elementborderwidthscreen distance-1elementBorderWidthThe width of the borders of the slider and the arrows.
-highlightbackgroundcolor#d9d9d9highlightBackgroundThe color of the focus ring while the scrollbar has no focus, in the look of Tk on X11.
-highlightcolorcolor#000000highlightColorThe color of the focus ring while the scrollbar has the focus, in the look of Tk on X11.
-highlightthicknessscreen distance0highlightThicknessThe width of the focus ring, in the look of Tk on X11.
-jumpboolean0jumpWhether a drag of the slider scrolls only at the release of the button.
-orientorientationverticalorientThe direction of the scrollbar: horizontal or vertical.
-reliefreliefsunkenreliefThe 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.
-takefocusstringemptytakeFocusWhether the Tab key can move the focus to the scrollbar.
-troughcolorcolor#b3b3b3troughColorThe color of the trough, in the look of Tk on X11.
-widthscreen distance11widthThe width of the short side of the scrollbar.

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

% scrollbar .activebackground -activebackground {#336699}
> .activebackground cget -activebackground
#336699
% scrollbar .activebackground2 -activebackground nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor

-activerelief RELIEF

The relief of the active element.

In Tk, the element of activate has this 3-D look. ztk stores the value with no effect.

Values: flat, groove, raised, ridge, solid, sunken.

% scrollbar .activerelief -activerelief groove
> .activerelief cget -activerelief
groove
% scrollbar .activerelief2 -activerelief bumpy
bad relief "bumpy": must be flat, groove, raised, ridge, solid, or sunken
-errorcode TCL LOOKUP INDEX relief bumpy

-background COLOR

The background color of the scrollbar.

The color behind the content. -bg is the same option. A color is a name such as red, or #RGB, #RRGGBB, or #RRRRGGGGBBBB.

scrollbar with -orient horizontal and -background {#fde68a}-background {#fde68a}scrollbar with -orient horizontal and -background {#bfdbfe}-background {#bfdbfe}
Each with -orient horizontal.
% scrollbar .background -background {#336699}
> .background cget -background
#336699
% scrollbar .background2 -background nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor

-borderwidth DISTANCE

The width of the border of the scrollbar.

The width of the border around the scrollbar. -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.

scrollbar with -orient horizontal -relief solid and -borderwidth 0-borderwidth 0scrollbar with -orient horizontal -relief solid and -borderwidth 1-borderwidth 1scrollbar with -orient horizontal -relief solid and -borderwidth 4-borderwidth 4
Each with -orient horizontal -relief solid.
% scrollbar .borderwidth -borderwidth 4
> .borderwidth cget -borderwidth
4
% scrollbar .borderwidth2 -borderwidth x
bad screen distance "x"
-errorcode TK VALUE PIXELS

-command PREFIX

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

When the user drags the slider or clicks the trough, the scrollbar adds the words of the change and runs the command at the global level. The words are moveto FRACTION, or scroll N units or scroll N pages. These are the arguments of xview and yview of a scrollable widget, so the usual value is {.list yview} for a listbox .list.

% scrollbar .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 scrollbar.

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.

% scrollbar .cursor -cursor hand2
> .cursor cget -cursor
hand2
% scrollbar .cursor2 -cursor nocursor
bad cursor spec "nocursor"
-errorcode TK VALUE CURSOR

-elementborderwidth DISTANCE

The width of the borders of the slider and the arrows.

In Tk, the slider and the arrows have a 3-D border of this width, and -1 uses -borderwidth. ztk stores the value with no effect.

% scrollbar .elementborderwidth -elementborderwidth 4
> .elementborderwidth cget -elementborderwidth
4
% scrollbar .elementborderwidth2 -elementborderwidth x
bad screen distance "x"
-errorcode TK VALUE PIXELS

-highlightbackground COLOR

The color of the focus ring while the scrollbar has no focus, in the look of Tk on X11.

The color of the highlight ring of -highlightthickness while the scrollbar does not have the focus. ztk stores the value with no effect.

% scrollbar .highlightbackground -highlightbackground {#336699}
> .highlightbackground cget -highlightbackground
#336699
% scrollbar .highlightbackground2 -highlightbackground nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor

-highlightcolor COLOR

The color of the focus ring while the scrollbar has the focus, in the look of Tk on X11.

The color of the highlight ring of -highlightthickness while the scrollbar has the focus. ztk stores the value with no effect.

% scrollbar .highlightcolor -highlightcolor {#336699}
> .highlightcolor cget -highlightcolor
#336699
% scrollbar .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 scrollbar that shows the focus. The modern theme draws the focus with the stylesheet.

% scrollbar .highlightthickness -highlightthickness 4
> .highlightthickness cget -highlightthickness
4
% scrollbar .highlightthickness2 -highlightthickness x
bad screen distance "x"
-errorcode TK VALUE PIXELS

-jump BOOLEAN

Whether a drag of the slider scrolls only at the release of the button.

With a false value, the scrollbar runs -command at each move of a drag. With a true value, it runs -command once, at the release.

% scrollbar .jump -jump 1
> .jump cget -jump
1
% scrollbar .jump2 -jump maybe
expected boolean value but got "maybe"
-errorcode TCL VALUE NUMBER

-orient WORD

The direction of the scrollbar: horizontal or vertical.

The scrollbar lies along this direction.

Values: vertical, horizontal.

scrollbar with -orient vertical-orient verticalscrollbar with -orient horizontal-orient horizontal
% scrollbar .orient -orient horizontal
> .orient cget -orient
horizontal
% scrollbar .orient2 -orient bogus
bad orientation "bogus": must be vertical or horizontal
-errorcode TCL LOOKUP INDEX orientation 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.

scrollbar with -orient horizontal -borderwidth 2 and -relief flat-relief flatscrollbar with -orient horizontal -borderwidth 2 and -relief raised-relief raisedscrollbar with -orient horizontal -borderwidth 2 and -relief sunken-relief sunkenscrollbar with -orient horizontal -borderwidth 2 and -relief solid-relief solid
Each with -orient horizontal -borderwidth 2.
% scrollbar .relief -relief groove
> .relief cget -relief
groove
% scrollbar .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 an arrow or the trough repeats its action after this delay. ztk stores the value with no effect: a press moves one step.

% scrollbar .repeatdelay -repeatdelay 5
> .repeatdelay cget -repeatdelay
5
% scrollbar .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 action at this interval. ztk stores the value with no effect.

% scrollbar .repeatinterval -repeatinterval 5
> .repeatinterval cget -repeatinterval
5
% scrollbar .repeatinterval2 -repeatinterval x
expected integer but got "x"
-errorcode TCL VALUE NUMBER

-takefocus TEXT

Whether the Tab key can move the focus to the scrollbar.

1 puts the scrollbar 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.

% scrollbar .takefocus -takefocus 1
> .takefocus cget -takefocus
1

ztk stores each value of the option with no check.

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

% scrollbar .troughcolor -troughcolor {#336699}
> .troughcolor cget -troughcolor
#336699
% scrollbar .troughcolor2 -troughcolor nocolor
unknown color name "nocolor"
-errorcode TK LOOKUP COLOR nocolor

-width DISTANCE

The width of the short side of the scrollbar.

The size of the scrollbar across 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.

scrollbar with -orient horizontal and -width 8-width 8scrollbar with -orient horizontal and -width 15-width 15scrollbar with -orient horizontal and -width 30-width 30
Each with -orient horizontal.
% scrollbar .width -width 4
> .width cget -width
4
% scrollbar .width2 -width x
bad screen distance "x"
-errorcode TK VALUE PIXELS

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

# The listbox shows its first items, so the slider starts at 0.
% listbox .files -yscrollcommand {.vbar set}
> scrollbar .vbar -command {.files yview}
> pack .vbar -side right -fill y
> pack .files -side left -fill both -expand 1
> .files insert end {*}[lrepeat 40 item]
> update
> lindex [.vbar get] 0
0.0

% winfo class [scrollbar .go]
Scrollbar

Errors

% scrollbar .x -foo 1
unknown option "-foo"
-errorcode TK LOOKUP OPTION -foo

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

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

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