ttk::scrollbar(3tk)
π ttk::scrollbar β the it-girl of viewport control π
okay bestie, so this is the manual page for ttk::scrollbar, part of the Tk Themed Widget crew. It's giving "let me hold your document down while you scroll through it" energy, and honestly? Iconic. Let's get into it.
β¨ NAME β¨
ttk::scrollbar β control the viewport of a scrollable widget. That's the whole job, and she does it flawlessly π
πΈ SYNOPSIS πΈ
ttk::scrollbar pathName ?options...?
π¦ DESCRIPTION π¦
So like, ttk::scrollbar widgets are typically linked to an associated window that displays a document of some sort β think a file you're editing, or a drawing. You know the vibe.
A scrollbar shows a thumb in the middle portion of the scrollbar, and that thumb's position and size tell you stuff about the portion of the document that's currently visible in the associated window. The thumb can be dragged by the user to control the visible region. Obsessed with her.
And depending on the theme, two or more arrow buttons may also be present β those are for scrolling the visible region in discrete units. Little steps, you know? π
β STANDARD OPTIONS β
-class-cursor-style-takefocus
See the ttk_widget manual entry for the deets on all the standard options, bestie.
π WIDGET-SPECIFIC OPTIONS π
π -command
- Command-Line Name:
-command - Database Name:
command - Database Class:
Command
A Tcl script prefix that gets evaluated to change the view in the widget associated with the scrollbar. Whenever the user requests a view change by messing with the scrollbar, additional arguments get appended to the value of this option β and the exact form of those is described down in SCROLLING COMMANDS, so don't skip that part π
This option typically consists of a two-element list: the name of a scrollable widget, followed by either xview (for horizontal scrollbars) or yview (for vertical scrollbars). That's the classic combo, no cap.
π -orient
- Command-Line Name:
-orient - Database Name:
orient - Database Class:
Orient
One of horizontal or vertical. Specifies the orientation of the scrollbar. That's it, that's the whole thing β she's decisive.
π WIDGET COMMAND π
On top of the standard cget, configure, identify element, instate, state and style commands (peep ttk::widget for those), scrollbar widgets also support these extra commands:
pathName getβ Returns the scrollbar settings as a list, and those elements are literally the arguments to the most recentsetwidget command. Like a little receipt of what you last told her πpathName set first lastβ This command is normally invoked by the scrollbar's associated widget from an-xscrollcommandor-yscrollcommandcallback. It specifies the visible range to be displayed.firstandlastare real fractions between 0 and 1.
π₯ INTERNAL COMMANDS π₯
These following widget commands are used internally by the TScrollbar widget class bindings. Not your business normally, but here they are anyway because we keep all the facts π«Ά
pathName delta deltaX deltaYβ Returns a real number indicating the fractional change in the scrollbar setting that corresponds to a given change in thumb position. For example, if the scrollbar is horizontal, the result indicates how much the scrollbar setting must change to move the thumbdeltaXpixels to the right (anddeltaYis ignored in this case). If the scrollbar is vertical, the result indicates how much the scrollbar setting must change to move the thumbdeltaYpixels down. The arguments and the result may be zero or negative. Math girl summer.pathName fraction x yβ Returns a real number between 0 and 1 indicating where the point given byxandylies in the trough area of the scrollbar, where 0.0 corresponds to the top or left of the trough and 1.0 corresponds to the bottom or right.xandyare pixel coordinates relative to the scrollbar widget. And ifxandyrefer to a point outside the trough, the closest point in the trough is used β she snaps to the nearest vibe β¨
π« SCROLLING COMMANDS π«
When the user interacts with the scrollbar β like dragging the thumb β the scrollbar notifies the associated widget that it must change its view. It does this by evaluating a Tcl command generated from the scrollbar's -command option. The command may take any of the following forms. In each case, prefix is the contents of the -command option, which usually has a form like .t yview.
prefix moveto fractionβfractionis a real number between 0 and 1. The widget should adjust its view so that the point given byfractionappears at the beginning of the widget. Iffractionis 0 it refers to the beginning of the document.1.0refers to the end of the document,0.333refers to a point one-third of the way through the document, and so on. Ratios, bestie, it's all ratios πprefix scroll number pagesβ The widget should adjust its view bynumberpages. It's up to the widget to define the meaning of a page; typically it's slightly less than what fits in the window, so that there's a slight overlap between the old and new views.numberis either1, which means the next page should become visible, or-1, which means the previous page should become visible.prefix scroll number unitsβ The widget should adjust its view bynumberunits. The units are defined in whatever way makes sense for the widget β like characters or lines in a text widget.numberis either1, which means one unit should scroll off the top or left of the window, or-1, which means one unit should scroll off the bottom or right of the window.
π WIDGET STATES π
The scrollbar automatically sets the disabled state bit when the entire range is visible (range is 0.0 to 1.0), and clears it otherwise. She also sets the active and pressed state flags of individual elements, based on the position and state of the mouse pointer. She's always watching ππ
π§ EXAMPLE π§
Here's the whole setup, copy-paste ready:
set f [frame .f]
ttk::scrollbar $f.hsb -orient horizontal -command [list $f.t xview]
ttk::scrollbar $f.vsb -orient vertical -command [list $f.t yview]
text $f.t -xscrollcommand [list $f.hsb set] -yscrollcommand [list $f.vsb set]
grid $f.t -row 0 -column 0 -sticky nsew
grid $f.vsb -row 0 -column 1 -sticky nsew
grid $f.hsb -row 1 -column 0 -sticky nsew
grid columnconfigure $f 0 -weight 1
grid rowconfigure $f 0 -weight 1
pack $f
π¨ STYLING OPTIONS π¨
The class name for a ttk::scrollbar is TScrollbar.
Dynamic states: active, disabled.
TScrollbar (or, more specifically, Vertical.TScrollbar and Horizontal.TScrollbar) styling options that are configurable with ttk::style are:
-arrowcolorcolor-arrowsizeamount-backgroundcolor-bordercolorcolor-darkcolorcolor (color of the dark part of the 3D relief)-foregroundcolor-gripsizesize (number of screen units)-lightcolorcolor (color of the light part of the 3D relief)-troughcolorcolor
Heads up bestie: some of these options are only available for specific themes. Don't come for her if your theme doesn't do the thing π«Ά
See the ttk::style manual page for info on how to configure ttk styles.
π SEE ALSO π
ttk::widget(3tk)scrollbar(3tk)
π KEYWORDS π
scrollbar, widget
and that's the whole page, bestie β every last detail, no cap π
This one's from Tk 8.5, and it's the ttk::scrollbar(3tk) manual page, so go forth and scroll responsibly β¨π¦π
π¦ where this page comes from
- debian trixie: tk9.0-doc 9.0.1-3
- ubuntu questing: tk9.0-doc 9.0.2-1
- ubuntu resolute: tk9.0-doc 9.0.3-1
- ubuntu stonking: tk9.0-doc 9.0.4-1
- Copyright (c) 1994-1996 Sun Microsystems, Inc
- Copyright (c) 2004 Joe English
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms