Next / Previous / Contents / Shipman's homepage

42. ttk.Scrollbar

This is the ttk version of Section 22, “The Scrollbar widget”. To create a ttk.Scrollbar as the child of a given parent widget, where the option values are given in Table 59, “ttk.Scrollbar options”:

    w = ttk.Scrollbar(parent, option=value, ...)

Table 59. ttk.Scrollbar options

class_ The widget class name. This may be specified when the widget is created, but cannot be changed later. For an explanation of widget classes, see Section 27, “Standardizing appearance”.
command A procedure to be called whenever the scrollbar is moved. For a discussion of the calling sequence, see Section 22.1, “The Scrollbar command callback”.
cursor The cursor that will appear when the mouse is over the scrollbar; see Section 5.8, “Cursors”.
orient Set orient=tk.HORIZONTAL for a horizontal scrollbar, orient=tk.VERTICAL for a vertical one (the default orientation).
style The style to be used in rendering this scrollbar; see Section 49, “Using and customizing ttk styles”.
takefocus By default, a ttk.Scrollbar will not be included in focus traversal; see Section 53, “Focus: routing keyboard input”. To add the widget to focus traversal, use takefocus=True.

These options of a Tkinter Scrollbar widget are not supported by the ttk.Scrollbar constructor:

Table 60. Tkinter options not in ttk.Scrollbar

activebackground Use a style map to control the background option; see Section 50.2, “ttk style maps: dynamic appearance changes”.
activerelief Use a style map to control the relief option; see Section 50.2, “ttk style maps: dynamic appearance changes”.
background or bg Configure the background option using a style; this option controls the color of the slider. The bg abbreviation is not supported.
borderwidth or bd Configure the borderwidth option using a style. The bd abbreviation is not supported.
elementborderwidth Not supported.
highlightbackground Not supported.
highlightcolor Not supported.
highlightthickness Not supported.
jump Not supported.
relief Configure this option using a style.
repeatdelay Not supported.
repeatinterval Not supported.
troughcolor Configure this option using a style.
width Configure this option using a style. You may find that configuring arrowsize is a better choice; in some themes, increasing the width may not increase the size of the arrowheads.

Methods on a ttk.Scrollbar include all those described in Section 46, “Methods common to all ttk widgets”, plus:

.delta(dx, dy)

Given a mouse movement of (dx, dy) in pixels, this method returns the float value that should be added to the current slider position to achieve that same movement. The value must be in the closed interval [-1.0, 1.0].

.fraction(x, y)

Given a pixel location (x, y), this method returns the corresponding normalized slider position in the interval [0.0, 1.0] that is closest to that location.

.get()

Returns two numbers (a, b) describing the current position of the slider. The a value gives the position of the left or top edge of the slider, for horizontal and vertical scrollbars respectively; the b value gives the position of the right or bottom edge. Each value is in the interval [0.0, 1.0] where 0.0 is the leftmost or top position and 1.0 is the rightmost or bottom position. For example, if the slider extends from halfway to three-quarters of the way along the trough, you might get back the tuple (0.5,0.75).

.set(first, last)

To connect a scrollbar to another widget w, set w's xscrollcommand or yscrollcommand to the scrollbar's .set method. The arguments have the same meaning as the values returned by the .get() method. Please note that moving the scrollbar's slider does not move the corresponding widget.