scale(n)
β¨ NAME β¨
scale β create and manipulate 'scale' value-controlled slider widgets
okay so first things first, bestie: this is the scale(n) page, and it lives in Tk Built-In Commands. She's the icon behind that little draggable slider in a trough. You know the one. You've poked it. π
π SYNOPSIS π
scale pathName ?options?
πΈ STANDARD OPTIONS πΈ
Here's the standard-options lineup, laid out exactly the way the page serves it:
-activebackground,-foreground,-relief-background,-highlightbackground,-repeatdelay-borderwidth,-highlightcolor,-repeatinterval-cursor,-highlightthickness,-takefocus-font,-orient,-troughcolor
See the options manual entry for details on the standard options. (That's where the lore lives, iykyk.)
π WIDGET-SPECIFIC OPTIONS π
These are the ones that are hers, not inherited. Each one comes with a command-line name, a database name, and a database class, so I'm giving you all three every single time. No cap.
-bigincrementβ command-line name-bigincrement, database namebigIncrement, database classBigIncrement. Some interactions with the scale cause its value to change by "large" increments, and this option sets exactly how big those large increments are. If you specify it as0, the large increments default to1/10the range of the scale.-commandβ command-line name-command, database namecommand, database classCommand. Specifies the prefix of a Tcl command to invoke whenever the scale's value is changed via a widget command. The actual command is this option, then a space, then a real number showing the scale's new value. It's giving "call me when you change, bestie." π«Ά-digitsβ command-line name-digits, database namedigits, database classDigits. An integer specifying how many significant digits should be retained when converting the value of the scale to a string. If the number is negative or zero, the scale picks the smallest value that guarantees every possible slider position prints as a different string. Lowkey thoughtful of her.-fromβ command-line name-from, database namefrom, database classFrom. A real value corresponding to the left or top end of the scale.-labelβ command-line name-label, database namelabel, database classLabel. A string to display as a label for the scale. For vertical scales the label goes just to the right of the top end of the scale. For horizontal scales it goes just above the left end of the scale. If you specify it as an empty string, no label is displayed. (She respects the "no thoughts, no label" request. π)-lengthβ command-line name-length, database namelength, database classLength. Specifies the desired long dimension of the scale in screen units β that means any of the forms acceptable toTk_GetPixels. For vertical scales this is the scale's height; for horizontal scales it's the scale's width.-resolutionβ command-line name-resolution, database nameresolution, database classResolution. A real value specifying the resolution for the scale. If this value is greater than zero, the scale's value will always be rounded to an even multiple of this value, and so will the endpoints of the scale. If the value is negative, no rounding occurs. Defaults to1, which means the value will be integral.-showvalueβ command-line name-showvalue, database nameshowValue, database classShowValue. Specifies a boolean value indicating whether or not the scale's current value is displayed. Main character gets to be seen, or not. Her choice. π-sliderlengthβ command-line name-sliderlength, database namesliderLength, database classSliderLength. Specifies the size of the slider, measured in screen units along the slider's long dimension. The value may be specified in any of the forms acceptable toTk_GetPixels.-sliderreliefβ command-line name-sliderrelief, database namesliderRelief, database classSliderRelief. Specifies the relief to use when drawing the slider, such asraisedorsunken.-stateβ command-line name-state, database namestate, database classState. Specifies one of three states for the scale:normal,active, ordisabled. If the scale is disabled then the value may not be changed and the scale will not activate. If the scale is active, the slider is displayed using the color specified by the-activebackgroundoption. Glow-up mode, basically. β¨-tickintervalβ command-line name-tickinterval, database nametickInterval, database classTickInterval. Must be a real value. Determines the spacing between the numerical tick marks displayed below or to the left of the slider. The values will all be displayed with the same number of decimal places, and that number will be enough to ensure they are all accurate to within 20% of a tick interval. If0, no tick marks will be displayed.-toβ command-line name-to, database nameto, database classTo. Specifies a real value corresponding to the right or bottom end of the scale. Heads up: this value may be either less than or greater than the-fromoption. She's flexible like that. π¦-variableβ command-line name-variable, database namevariable, database classVariable. Specifies the name of a global variable to link to the scale. Whenever the value of the variable changes, the scale will update to reflect this value. Whenever the scale is manipulated interactively, the variable will be modified to reflect the scale's new value. It's a two-way group chat, fr fr. π¬-widthβ command-line name-width, database namewidth, database classWidth. Specifies the desired narrow dimension of the scale in screen units β again, any of the forms acceptable toTk_GetPixels. For vertical scales this is the scale's width; for horizontal scales it's the scale's height.
π¦ DESCRIPTION π¦
The scale command creates a new window (given by the pathName argument) and makes it into a scale widget. Additional options, described above, may be specified on the command line or in the option database to configure aspects of the scale such as its colors, orientation, and relief. The scale command returns its pathName argument.
At the time this command is invoked, there must not exist a window named pathName, but pathName's parent must exist. Name collisions are not the vibe. π
A scale is a widget that displays a rectangular trough and a small slider. The trough corresponds to a range of real values (determined by the -from, -to, and -resolution options), and the position of the slider selects a particular real value. The slider's position β and therefore the scale's value β may be adjusted with the mouse or keyboard, as described in the BINDINGS section below. Whenever the scale's value is changed, a Tcl command is invoked (using the -command option) to notify other interested widgets of the change. On top of that, the value of the scale can be linked to a Tcl variable (using the -variable option), so that changes in either one are reflected in the other.
Three annotations may be displayed in a scale widget:
- a label appearing at the top right of the widget (top left for horizontal scales),
- a number displayed just to the left of the slider (just above the slider for horizontal scales),
- a collection of numerical tick marks just to the left of the current value (just below the trough for horizontal scales).
Each of these three annotations may be enabled or disabled using the configuration options. Pick your accessories, bestie. π
π οΈ WIDGET COMMAND π οΈ
The scale command creates a new Tcl command whose name is pathName. This command may be used to invoke various operations on the widget. It has the following general form:
pathName option ?arg ...?
Option and the args determine the exact behavior of the command. The following commands are possible for scale widgets:
pathName cget option
Returns the current value of the configuration option given by option. Option may have any of the values accepted by the scale command.
pathName configure ?option? ?value option value ...?
Query or modify the configuration options of the widget. If no option is specified, returns a list describing all of the available options for pathName (see Tk_ConfigureInfo for information on the format of this list). If option is specified with no value, then the command returns a list describing the one named option β and that list will be identical to the corresponding sublist of the value returned when no option is specified. If one or more option-value pairs are specified, then the command modifies the given widget option(s) to have the given value(s); in that case the command returns an empty string. Option may have any of the values accepted by the scale command. She's a whole config queen. π
pathName coords ?value?
Returns a list whose elements are the x and y coordinates of the point along the centerline of the trough that corresponds to value. If value is omitted, then the scale's current value is used.
pathName get ?x y?
If x and y are omitted, returns the current value of the scale. If x and y are specified, they give pixel coordinates within the widget, and the command returns the scale value corresponding to the given pixel. Only one of x or y is used: for horizontal scales y is ignored, and for vertical scales x is ignored. Loving the "pick a lane" energy. π¦
pathName identify x y
Returns a string indicating what part of the scale lies under the coordinates given by x and y. A return value of slider means that the point is over the slider; trough1 means that the point is over the portion of the slider above or to the left of the slider; and trough2 means that the point is over the portion of the slider below or to the right of the slider. If the point is not over one of these elements, an empty string is returned.
pathName set value
This command is invoked to change the current value of the scale, and hence the position at which the slider is displayed. Value gives the new value for the scale. Small but crucial caveat: the command has no effect if the scale is disabled. π«
π BINDINGS π
okay so Tk automatically creates class bindings for scales, and they give you these default behaviors. bestie, where the behavior is different for vertical and horizontal scales, the horizontal behavior is described in parentheses. periodt. π
- if button 1 is pressed in the trough, the scale's value will be incremented or decremented by the value of the
-resolutionoption so that the slider moves in the direction of the cursor. if the button is held down, the action auto-repeats. π - if button 1 is pressed over the slider, the slider can be dragged with the mouse. π±οΈ
- if button 1 is pressed in the trough with the Control key down, the slider moves all the way to the end of its range, in the direction towards the mouse cursor. β¨
- if button 2 is pressed, the scale's value is set to the mouse position. if the mouse is dragged with button 2 down, the scale's value changes with the drag. π
- the Up and Left keys move the slider up (left) by the value of the
-resolutionoption. - the Down and Right keys move the slider down (right) by the value of the
-resolutionoption. - Control-Up and Control-Left move the slider up (left) by the value of the
-bigincrementoption. - Control-Down and Control-Right move the slider down (right) by the value of the
-bigincrementoption. - Home moves the slider to the top (left) end of its range.
- End moves the slider to the bottom (right) end of its range.
if the scale is disabled using the -state option then none of the above bindings have any effect. like, zero. nada. π
the behavior of scales can be changed by defining new bindings for individual widgets or by redefining the class bindings. slay. π
π SEE ALSO π
ttk::scale(n) β yes, that's the whole SEE ALSO. go read it, bestie. π¦
π KEYWORDS π
scale, slider, trough, widget β the whole keyword squad. π«Ά
π aaaand that's the page! footer tea: Tk 4.1, scale(n) β no separate date line to quote, so we're not inventing one. mwah! π
π¦ where this page comes from
- alpine 3.23: tk9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tk9-doc 9.0.3-r2 Β· TCL
- fedora 43: tk 1:9.0.2-1.fc43 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 43: tk 1:9.0.2-1.fc43 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 44: tk 1:9.0.2-1.fc44 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- fedora 44: tk 1:9.0.2-1.fc44 Β· TCL AND HPND-Pbmplus AND CC-BY-SA-3.0 AND MIT-open-group AND MIT
- nixos 26.05: tk 9.0.3
- nixpkgs unstable: tk 9.1.0
- Copyright (c) 1990-1994 The Regents of the University of California
- Copyright (c) 1994-1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms