1ttk::intro(n) Tk Themed Widget ttk::intro(n)
2
3
4
5______________________________________________________________________________
6
8 ttk::intro - Introduction to the Tk theme engine
9_________________________________________________________________
10
12 The Tk themed widget set is based on a revised and enhanced version of
13 TIP #48 (http://tip.tcl.tk/48) specified style engine. The main con‐
14 cepts are described below. The basic idea is to separate, to the
15 extent possible, the code implementing a widget's behavior from the
16 code implementing its appearance. Widget class bindings are primarily
17 responsible for maintaining the widget state and invoking callbacks;
18 all aspects of the widgets appearance is
19
21 A theme is a collection of elements and styles that determine the look
22 and feel of the widget set. Themes can be used to:
23
24 · Isolate platform differences (X11 vs. classic Windows vs. XP vs.
25 Aqua ...)
26
27 · Adapt to display limitations (low-color, grayscale, monochrome,
28 tiny screens)
29
30 · Accessibility (high contrast, large type)
31
32 · Application suite branding
33
34 · Blend in with the rest of the desktop (Gnome, KDE, Java)
35
36 · And, of course: eye candy.
37
39 An element displays an individual part of a widget. For example, a
40 vertical scrollbar widget contains uparrow, downarrow, trough and
41 slider elements.
42
43 Element names use a recursive dotted notation. For example, uparrow
44 identifies a generic arrow element, and Scrollbar.uparrow and Com‐
45 bobox.uparrow identify widget-specific elements. When looking for an
46 element, the style engine looks for the specific name first, and if an
47 element of that name is not found it looks for generic elements by
48 stripping off successive leading components of the element name.
49
50 Like widgets, elements have options which specify what to display and
51 how to display it. For example, the text element (which displays a
52 text string) has -text, -font, -foreground, -background, -underline,
53 and -width options. The value of an element option is taken from:
54
55 · An option of the same name and type in the widget containing the
56 element;
57
58 · A dynamic setting specified by style map and the current state;
59
60 · The default setting specified by style configure; or
61
62 · The element's built-in default value for the option.
63
65 A layout specifies which elements make up a widget and how they are
66 arranged. The layout engine uses a simplified version of the pack
67 algorithm: starting with an initial cavity equal to the size of the
68 widget, elements are allocated a parcel within the cavity along the
69 side specified by the -side option, and placed within the parcel
70 according to the -sticky option. For example, the layout for a hori‐
71 zontal scrollbar
72 ttk::style layout Horizontal.TScrollbar {
73 Scrollbar.trough -children {
74 Scrollbar.leftarrow -side left -sticky w
75 Scrollbar.rightarrow -side right -sticky e
76 Scrollbar.thumb -side left -expand true -sticky ew
77 }
78 }
79 By default, the layout for a widget is the same as its class name.
80 Some widgets may override this (for example, the ttk::scrollbar widget
81 chooses different layouts based on the -orient option).
82
84 In standard Tk, many widgets have a -state option which (in most cases)
85 is either normal or disabled. Some widgets support additional states,
86 such as the entry widget which has a readonly state and the various
87 flavors of buttons which have active state.
88
89 The themed Tk widgets generalizes this idea: every widget has a bitmap
90 of independent state flags. Widget state flags include active, dis‐
91 abled, pressed, focus, etc., (see ttk::widget(n) for the full list of
92 state flags).
93
94 Instead of a -state option, every widget now has a state widget command
95 which is used to set or query the state. A state specification is a
96 list of symbolic state names indicating which bits are set, each
97 optionally prefixed with an exclamation point indicating that the bit
98 is cleared instead.
99
100 For example, the class bindings for the ttk::button widget are:
101 bind TButton <Enter>{ %W state active }
102 bind TButton <Leave>{ %W state !active }
103 bind TButton <ButtonPress-1>{ %W state pressed }
104 bind TButton <Button1-Leave>{ %W state !pressed }
105 bind TButton <Button1-Enter>{ %W state pressed }
106 bind TButton <ButtonRelease-1>\
107 { %W instate {pressed} { %W state !pressed ; %W invoke } }
108 This specifies that the widget becomes active when the pointer enters
109 the widget, and inactive when it leaves. Similarly it becomes pressed
110 when the mouse button is pressed, and !pressed on the ButtonRelease
111 event. In addition, the button unpresses if pointer is dragged outside
112 the widget while Button-1 is held down, and represses if it's dragged
113 back in. Finally, when the mouse button is released, the widget's
114 -command is invoked, but only if the button is currently in the pressed
115 state. (The actual bindings are a little more complicated than the
116 above, but not by much).
117
118 Note to self: rewrite that paragraph. It's horrible.
119
121 Each widget is associated with a style, which specifies values for ele‐
122 ment options. Style names use a recursive dotted notation like layouts
123 and elements; by default, widgets use the class name to look up a style
124 in the current theme. For example:
125 ttk::style configure TButton \
126 -background #d9d9d9 \
127 -foreground black \
128 -relief raised \
129 ;
130 Many elements are displayed differently depending on the widget state.
131 For example, buttons have a different background when they are active,
132 a different foreground when disabled, and a different relief when
133 pressed. The style map command specifies dynamic option settings for a
134 particular style:
135 ttk::style map TButton \
136 -background [list disabled #d9d9d9 active #ececec] \
137 -foreground [list disabled #a3a3a3] \
138 -relief [list {pressed !disabled} sunken] \
139 ;
140
142 ttk::widget(n), ttk::style(n)
143
144
145
146Tk 8.5 ttk::intro(n)