Scrollbar
A scrollbar that drives a scrollable widget — a Text,
Listbox, Treeview, Canvas, or
Entry. TScrollbar is the themed version (preferred); Scrollbar
is the classic one.
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 tells the widget where to move. Wire the two callbacks once, after creating both:
const lb = app.Listbox();
const sb = app.TScrollbar({ orient: 'vertical' });
sb.pack.configure({ side: 'right', fill: 'y' });
lb.pack.configure({ side: 'left', fill: 'both', expand: true });
// widget → scrollbar (position) and scrollbar → widget (scroll command)
__native_tcl(lb._id, 'configure', '-yscrollcommand', `${sb._id} set`);
__native_tcl(sb._id, 'configure', '-command', `${lb._id} yview`);
lb.insert('end', ...Array.from({ length: 50 }, (_, i) => `Item ${i + 1}`));
For a horizontal scrollbar, use orient: 'horizontal' and the xScrollCommand
/ xview pair instead. The wiring uses the
__native_tcl escape hatch because the two callbacks pass
Tcl-level arguments between the widgets.
Options
| Option | Type | Description |
|---|---|---|
orient |
string | 'vertical' or 'horizontal' (creation-time only). |
style |
string | A ttk style name (TScrollbar only). |
The classic Scrollbar also takes width, troughColor, background, and
relief.
Methods
A scrollbar has no methods you call directly — it's driven entirely by the two
configure links above. It does support the inherited widget methods (layout,
bind, …); see Widget basics.
See also
Text,Listbox,Treeview— the widgets you scroll- System & files — the
__native_tclescape hatch