Home › Tk Themed Widget Tk
ttk::widget
Standard options and commands supported by Tk themed widgets
literal type exactly as shown
argument replace with your value
?optional? may be omitted
Description#
This manual describes common widget options and commands.
Standard options#
The following options are supported by all Tk themed widgets:
-class#-
Database name undefinedDatabase class undefinedSpecifies the window class. The class is used when querying the option database for the window's other options, to determine the default bindtags for the window, and to select the widget's default layout and style. This is a read-only option: it may only be specified when the window is created, and may not be changed with the
configurewidget command. -cursor#-
Database name cursorDatabase class CursorSpecifies the mouse cursor to be used for the widget. See
Tk_GetCursorand cursors(n) in the Tk reference manual for the legal values. If set to the empty string (the default), the cursor is inherited from the parent widget. -takefocus#-
Database name takeFocusDatabase class TakeFocusDetermines whether the window accepts the focus during keyboard traversal. Either
0,1, a command prefix (to which the widget path is appended, and which should return0or1), or the empty string. See options(n) in the Tk reference manual for the full description. -style#-
Database name styleDatabase class StyleMay be used to specify a custom widget style.
Scrollable widget options#
The following options are supported by widgets that are controllable by a scrollbar. See scrollbar(n) for more information
-xscrollcommand#-
Database name xScrollCommandDatabase class ScrollCommandA command prefix, used to communicate with horizontal scrollbars.
When the view in the widget's window changes, the widget will generate a Tcl command by concatenating the scroll command and two numbers. Each of the numbers is a fraction between 0 and 1 indicating a position in the document; 0 indicates the beginning, and 1 indicates the end. The first fraction indicates the first information in the widget that is visible in the window, and the second fraction indicates the information just after the last portion that is visible.
Typically the
-xscrollcommandoption consists of the path name of ascrollbarwidget followed by “set”, e.g. “.x.scrollbar set”. This will cause the scrollbar to be updated whenever the view in the window changes.If this option is set to the empty string (the default), then no command will be executed.
-yscrollcommand#-
Database name yScrollCommandDatabase class ScrollCommandA command prefix, used to communicate with vertical scrollbars. See the description of
-xscrollcommandabove for details.
Label options#
The following options are supported by labels, buttons, and other button-like widgets:
-anchor#-
Database name anchorDatabase class AnchorSpecifies how the information in the widget is positioned relative to the inner margins. Legal values are
n,ne,e,se,s,sw,w,nw, andcenter. See also-justify(for widgets supporting this option). -compound#-
Database name compoundDatabase class CompoundSpecifies how to display the image relative to the text, in the case both
-textand-imageare present. If set to the empty string (the default), the rules described in the "Elements" section of ttk::intro(n) explain which value is actually used. The other valid values are:- text
-
Display text only.
- image
-
Display image only.
- center
-
Display text centered on top of image.
- top
- bottom
- left
- right
-
Display image above, below, left of, or right of the text, respectively.
- none
-
Display the image if present, otherwise the text.
-font#-
Database name fontDatabase class FontFont to use for the text displayed by the widget.
-foreground#-
Database name textColorDatabase class TextColorThe widget's foreground color. If unspecified, the theme default is used.
-image#-
Database name imageDatabase class ImageSpecifies an image to display. This is a list of 1 or more elements. The first element is the default image name. The rest of the list is a sequence of statespec / value pairs as per
style map, specifying different images to use when the widget is in a particular state or combination of states. All images in the list should have the same size. -justify#-
Database name justifyDatabase class JustifyIf there are multiple lines of text, specifies how the lines are laid out relative to one another. One of
left,center, orright. See also-anchor(for widgets supporting this option). -padding#-
Database name paddingDatabase class PaddingSpecifies the internal padding for the widget. The padding is a list of up to four length specifications left top right bottom. If fewer than four elements are specified, bottom defaults to top, right defaults to left, and top defaults to left. In other words, a list of three numbers specify the left, vertical, and right padding; a list of two numbers specify the horizontal and the vertical padding; a single number specifies the same padding all the way around the widget.
-text#-
Database name textDatabase class TextSpecifies a text string to be displayed inside the widget (unless overridden by
-textvariablefor the widgets supporting this option). -textvariable#-
Database name textVariableDatabase class VariableSpecifies the name of a global variable whose value will be used in place of the
-textresource. -underline#-
Database name underlineDatabase class UnderlineIf set, specifies the integer index (0-based) of a character to underline in the text string.
endcorresponds to the last character,end-1 to the before last character, and so on. The underlined character is used for mnemonic activation. -width#-
Database name widthDatabase class WidthIf greater than zero, specifies how much space, in character widths, to allocate for the text label. If less than zero, specifies a minimum width. If zero or unspecified, the natural width of the text label is used. Note that some themes may specify a non-zero
-widthin the style. -wraplength#-
Database name wrapLengthDatabase class WrapLengthSpecifies the maximum line length. The value may have any of the forms acceptable to
Tk_GetPixels. If this option is less than or equal to zero, then automatic wrapping is not performed; otherwise the text is split into lines such that no line is longer than the specified value.
Entry options#
The following options are supported by entry, spinbox and combobox:
-placeholder#-
Database name placeHolderDatabase class PlaceHolderSpecifies a help text string to display if no text is otherwise displayed, that is when the widget is empty. The placeholder text is displayed using the values of the
-font,-justifyand-placeholderforegroundoptions. -placeholderforeground#-
Database name placeHolderForegroundDatabase class PlaceHolderForegroundSpecifies the foreground color of the placeholder text.
Compatibility options#
This option is only available for themed widgets that have “corresponding” traditional Tk widgets.
-state#-
Database name stateDatabase class StateMay be set to
normalordisabledto control thedisabledstate bit. This is a write-only option: setting it changes the widget state, but thestatewidget command does not affect the-stateoption.
Commands#
- pathName
cgetoption -
Returns the current value of the configuration option given by option.
- pathName
configure?option? ?value option value ...? -
Query or modify the configuration options of the widget. 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 this case the command returns an empty string. If option is specified with no value, then the command returns a list describing the named option: the elements of the list are the option name, database name, database class, default value, and current value. If no option is specified, returns a list describing all of the available options for pathName.
- pathName
identify elementx y -
Returns the name of the element under the point given by x and y, or an empty string if the point does not lie within any element. x and y are pixel coordinates relative to the widget. Some widgets accept other
identifysubcommands described in these widgets documentation. - pathName
instatestatespec ?script? -
Test the widget's state. If script is not specified, returns 1 if the widget state matches statespec and 0 otherwise. If script is specified, equivalent to
if {[pathName instate stateSpec]} script - pathName
state?stateSpec? -
Modify or inquire widget state. If stateSpec is present, sets the widget state: for each flag in stateSpec, sets the corresponding flag or clears it if prefixed by an exclamation point.
Returns a new state spec indicating which flags were changed:
set changes [pathName state spec] pathName state $changeswill restore pathName to the original state. If stateSpec is not specified, returns a list of the currently-enabled state flags.
- pathName
style -
Return the style used by the widget.
- pathName
xviewargs -
This command is used to query and change the horizontal position of the content in the widget's window. It can take any of the following forms:
- pathName
xview -
Returns a list containing two elements. Each element is a real fraction between 0 and 1; together they describe the horizontal span that is visible in the window. For example, if the first element is .2 and the second element is .6, 20% of the widget's content is off-screen to the left, the middle 40% is visible in the window, and 40% of the content is off-screen to the right. These are the same values passed to scrollbars via the
-xscrollcommandoption. - pathName
xviewindex -
Adjusts the view in the window so that the content given by index is displayed at the left edge of the window.
- pathName
xview movetofraction -
Adjusts the view in the window so that the character fraction of the way through the content appears at the left edge of the window. Fraction must be a fraction between 0 and 1.
- pathName
xview scrollnumber what -
This command shifts the view in the window left or right according to number and what. Number must be an integer or a float, but if it is a float then it is converted to an integer, rounded away from 0. What must be either
pagesorunits. If what ispagesthen the view adjusts by number screenfuls. If number is negative then characters farther to the left become visible; if it is positive then characters farther to the right become visible. If what isunits, the view adjusts left or right by number average-width characters on the display.
- pathName
- pathName
yviewargs -
This command is used to query and change the vertical position of the content in the widget's window. It can take any of the following forms:
- pathName
yview -
Returns a list containing two elements. Each element is a real fraction between 0 and 1; together they describe the vertical span that is visible in the window. For example, if the first element is .2 and the second element is .6, 20% of the widget's content is off-screen to the top, the middle 40% is visible in the window, and 40% of the content is off-screen to the bottom. These are the same values passed to scrollbars via the
-yscrollcommandoption. - pathName
yviewindex -
Adjusts the view in the window so that the content given by index is displayed at the top edge of the window.
- pathName
yview movetofraction -
Adjusts the view in the window so that the item fraction of the way through the content appears at the top edge of the window. Fraction must be a fraction between 0 and 1.
- pathName
yview scrollnumber what -
This command shifts the view in the window up or down according to number and what. Number must be an integer or a float, but if it is a float then it is converted to an integer, rounded away from 0. What must be either
pagesorunits. If what ispagesthen the view adjusts by number screenfuls. If number is negative then items farther to the top become visible; if it is positive then items farther to the bottom become visible. If what isunits, the view adjusts up or down by number average-width characters on the display.
- pathName
Widget states#
The widget state is a bitmap of independent state flags. Widget state flags include:
active#-
The mouse cursor is over the widget and pressing a mouse button will cause some action to occur. (aka “prelight” (Gnome), “hot” (Windows), “hover”).
disabled#-
Widget is disabled under program control (aka “unavailable”, “inactive”).
focus#-
Widget has keyboard focus.
pressed#-
Widget is being pressed (aka “armed” in Motif).
selected#-
“On”, “true”, or “current” for things like checkbuttons and radiobuttons.
background#-
Windows and the Mac have a notion of an “active” or foreground window. The
backgroundstate is set for widgets in a background window, and cleared for those in the foreground window. readonly#-
Widget should not allow user modification.
alternate#-
A widget-specific alternate display format. For example, used for checkbuttons and radiobuttons in the “tristate” or “mixed” state, and for buttons with
-default active. invalid#-
The widget's value is invalid. (Potential uses: scale widget value out of bounds, entry widget value failed validation.)
hover#-
The mouse cursor is within the widget. This is similar to the
activestate; it is used in some themes for widgets that provide distinct visual feedback for the active widget in addition to the active element within the widget. user1-user6#-
Freely usable for other purposes
A state specification or stateSpec is a list of state names, optionally prefixed with an exclamation point (!) indicating that the bit is off.
Examples#
set b [ttk::button .b]
# Disable the widget:
$b state disabled
# Invoke the widget only if it is currently pressed and enabled:
$b instate {pressed !disabled} { .b invoke }
# Reenable widget:
$b state !disabled
Keywords#
Copyright#
- Copyright © 2004 Joe English