Scrollbar

A themed scrollbar that drives a scrollable widget — a Text, Listbox, Treeview, Canvas, or Entry.

Live preview

Drag the scrollbar; the Theme switcher in the toolbar restyles it live:

Live preview. In the Player's built-in docs viewer (scriptweaver --help), this renders Scrollbar as a live, theme-aware widget you can interact with.

Connecting a scrollbar

A scrollbar and its widget talk to each other in both directions: the widget tells the scrollbar how far it's scrolled, and the scrollbar scrolls the widget. sb.attach(widget) wires both directions in one call — the axis is taken from the scrollbar's orient:

const lb = app.Listbox();
const sb = app.Scrollbar({ orient: 'vertical' });

sb.pack.configure({ side: 'right', fill: 'y' });
lb.pack.configure({ side: 'left', fill: 'both', expand: true });

sb.attach(lb); // equivalently: lb.attachScrollbar(sb)

lb.insert('end', ...Array.from({ length: 50 }, (_, i) => `Item ${i + 1}`));

For a horizontal scrollbar, create it with orient: 'horizontal' and attach wires the x axis instead. (Pass an explicit axis — sb.attach(widget, 'x') — only to override what orient implies.)

For a widget that manages its own scrollbar, reach for ScrolledText or ScrolledFrame — no wiring needed at all.

Options

Option Type Description
orient string 'vertical' or 'horizontal' (creation-time only).
style string A ttk style name (TScrollbar only).

The underlying Tk scrollbar also takes width, troughColor, background, and relief — set them with sb.configure({ width: 16, … }).

Methods

Method Description
attach(widget[, axis]) Wire this scrollbar to a scrollable widget, both directions at once. axis ('x'/'y') defaults to the scrollbar's orient. The reciprocal is widget.attachScrollbar(sb).

Plus the inherited widget methods (layout, bind, …); see Widget basics.

See also