blob: 1d348c1ff2e4b3b9dc3e691cfe3ec76d28a15152 [file] [log] [blame]
Guilherme Polocda93aa2009-01-28 13:09:03 +00001:mod:`ttk` --- Tk themed widgets
2================================
3
4.. module:: ttk
5 :synopsis: Tk themed widget set
6.. sectionauthor:: Guilherme Polo <ggpolo@gmail.com>
7
8
9.. index:: single: ttk
10
Benjamin Peterson288618e2009-03-03 22:51:57 +000011The :mod:`ttk` module provides access to the Tk themed widget set, which has
12been introduced in Tk 8.5. If Python is not compiled against Tk 8.5 code may
13still use this module as long as Tile is installed. However, some features
14provided by the new Tk, like anti-aliased font rendering under X11, window
15transparency (on X11 you will need a composition window manager) will be
16missing.
Guilherme Polocda93aa2009-01-28 13:09:03 +000017
18The basic idea of :mod:`ttk` is to separate, to the extent possible, the code
19implementing a widget's behavior from the code implementing its appearance.
20
21
22.. seealso::
23
24 `Tk Widget Styling Support <http://www.tcl.tk/cgi-bin/tct/tip/48>`_
25 The document which brought up theming support for Tk
26
27
28Using Ttk
29---------
30
Benjamin Peterson288618e2009-03-03 22:51:57 +000031To start using Ttk, import its module::
Guilherme Polocda93aa2009-01-28 13:09:03 +000032
33 import ttk
34
Benjamin Peterson288618e2009-03-03 22:51:57 +000035But code like this::
Guilherme Polocda93aa2009-01-28 13:09:03 +000036
37 from Tkinter import *
38
Benjamin Peterson288618e2009-03-03 22:51:57 +000039may optionally want to use this::
Guilherme Polocda93aa2009-01-28 13:09:03 +000040
41 from Tkinter import *
42 from ttk import *
43
44And then several :mod:`ttk` widgets (:class:`Button`, :class:`Checkbutton`,
45:class:`Entry`, :class:`Frame`, :class:`Label`, :class:`LabelFrame`,
46:class:`Menubutton`, :class:`PanedWindow`, :class:`Radiobutton`, :class:`Scale`
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +000047and :class:`Scrollbar`) will automatically substitute for the Tk widgets.
Guilherme Polocda93aa2009-01-28 13:09:03 +000048
Benjamin Peterson288618e2009-03-03 22:51:57 +000049This has the direct benefit of using the new widgets, giving better look & feel
50across platforms, but be aware that they are not totally compatible. The main
51difference is that widget options such as "fg", "bg" and others related to
52widget styling are no longer present in Ttk widgets. Use :class:`ttk.Style` to
53achieve the same (or better) styling.
Guilherme Polocda93aa2009-01-28 13:09:03 +000054
55.. seealso::
56
57 `Converting existing applications to use the Tile widgets <http://tktable.sourceforge.net/tile/doc/converting.txt>`_
58 A text which talks in Tcl terms about differences typically found when
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +000059 converting applications to use the new widgets.
Guilherme Polocda93aa2009-01-28 13:09:03 +000060
61
62Ttk Widgets
63-----------
64
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +000065Ttk comes with 17 widgets, 11 of which already exist in Tkinter:
Guilherme Polocda93aa2009-01-28 13:09:03 +000066:class:`Button`, :class:`Checkbutton`, :class:`Entry`, :class:`Frame`,
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +000067:class:`Label`, :class:`LabelFrame`, :class:`Menubutton`,
68:class:`PanedWindow`, :class:`Radiobutton`, :class:`Scale` and
69:class:`Scrollbar`. The 6 new widget classes are: :class:`Combobox`,
70:class:`Notebook`, :class:`Progressbar`, :class:`Separator`,
71:class:`Sizegrip` and :class:`Treeview`. All of these classes are
Guilherme Polocda93aa2009-01-28 13:09:03 +000072subclasses of :class:`Widget`.
73
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +000074As said previously, you will notice changes in look-and-feel as well in the
Guilherme Polocda93aa2009-01-28 13:09:03 +000075styling code. To demonstrate the latter, a very simple example is shown below.
76
77Tk code::
78
79 l1 = Tkinter.Label(text="Test", fg="black", bg="white")
80 l2 = Tkinter.Label(text="Test", fg="black", bg="white")
81
82
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +000083Corresponding Ttk code::
Guilherme Polocda93aa2009-01-28 13:09:03 +000084
85 style = ttk.Style()
86 style.configure("BW.TLabel", foreground="black", background="white")
87
88 l1 = ttk.Label(text="Test", style="BW.TLabel")
89 l2 = ttk.Label(text="Test", style="BW.TLabel")
90
91For more information about TtkStyling_ read the :class:`Style` class
92documentation.
93
94Widget
95------
96
97:class:`ttk.Widget` defines standard options and methods supported by Tk
98themed widgets and is not supposed to be directly instantiated.
99
100
101Standard Options
102^^^^^^^^^^^^^^^^
103
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000104All the :mod:`ttk` widgets accept the following options:
Guilherme Polocda93aa2009-01-28 13:09:03 +0000105
106 +-----------+--------------------------------------------------------------+
107 | Option | Description |
108 +===========+==============================================================+
109 | class | Specifies the window class. The class is used when querying |
110 | | the option database for the window's other options, to |
111 | | determine the default bindtags for the window, and to select |
112 | | the widget's default layout and style. This is a read-only |
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000113 | | option which may only be specified when the window is |
114 | | created. |
Guilherme Polocda93aa2009-01-28 13:09:03 +0000115 +-----------+--------------------------------------------------------------+
116 | cursor | Specifies the mouse cursor to be used for the widget. If set |
117 | | to the empty string (the default), the cursor is inherited |
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000118 | | from the parent widget. |
Guilherme Polocda93aa2009-01-28 13:09:03 +0000119 +-----------+--------------------------------------------------------------+
120 | takefocus | Determines whether the window accepts the focus during |
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000121 | | keyboard traversal. 0, 1 or an empty string is returned. |
122 | | If 0, the window should be skipped entirely |
123 | | during keyboard traversal. If 1, the window |
124 | | should receive the input focus as long as it is viewable. |
125 | | An empty string means that the traversal scripts make the |
Guilherme Polocda93aa2009-01-28 13:09:03 +0000126 | | decision about whether or not to focus on the window. |
127 +-----------+--------------------------------------------------------------+
128 | style | May be used to specify a custom widget style. |
129 +-----------+--------------------------------------------------------------+
130
131
132Scrollable Widget Options
133^^^^^^^^^^^^^^^^^^^^^^^^^
134
135The following options are supported by widgets that are controlled by a
136scrollbar.
137
138 +----------------+---------------------------------------------------------+
139 | option | description |
140 +================+=========================================================+
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000141 | xscrollcommand | Used to communicate with horizontal scrollbars. |
Guilherme Polocda93aa2009-01-28 13:09:03 +0000142 | | |
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000143 | | When the view in the widget's window changes, the widget|
Guilherme Polocda93aa2009-01-28 13:09:03 +0000144 | | will generate a Tcl command based on the scrollcommand. |
145 | | |
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000146 | | Usually this option consists of the |
147 | | :meth:`Scrollbar.set` method of some scrollbar. This |
148 | | will cause |
Guilherme Polocda93aa2009-01-28 13:09:03 +0000149 | | the scrollbar to be updated whenever the view in the |
150 | | window changes. |
151 +----------------+---------------------------------------------------------+
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000152 | yscrollcommand | Used to communicate with vertical scrollbars. |
153 | | For more information, see above. |
Guilherme Polocda93aa2009-01-28 13:09:03 +0000154 +----------------+---------------------------------------------------------+
155
156
157Label Options
158^^^^^^^^^^^^^
159
160The following options are supported by labels, buttons and other button-like
161widgets.
162
163 +--------------+-----------------------------------------------------------+
164 | option | description |
165 +==============+===========================================================+
166 | text | Specifies a text string to be displayed inside the widget.|
167 +--------------+-----------------------------------------------------------+
168 | textvariable | Specifies a name whose value will be used in place of the |
169 | | text option resource. |
170 +--------------+-----------------------------------------------------------+
171 | underline | If set, specifies the index (0-based) of a character to |
172 | | underline in the text string. The underline character is |
173 | | used for mnemonic activation. |
174 +--------------+-----------------------------------------------------------+
175 | image | Specifies an image to display. This is a list of 1 or more|
176 | | elements. The first element is the default image name. The|
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000177 | | rest of the list is a sequence of statespec/value pairs as|
Guilherme Polocda93aa2009-01-28 13:09:03 +0000178 | | defined by :meth:`Style.map`, specifying different images |
179 | | to use when the widget is in a particular state or a |
180 | | combination of states. All images in the list should have |
181 | | the same size. |
182 +--------------+-----------------------------------------------------------+
183 | compound | Specifies how to display the image relative to the text, |
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000184 | | in the case both text and image options are present. |
Guilherme Polocda93aa2009-01-28 13:09:03 +0000185 | | Valid values are: |
186 | | |
187 | | * text: display text only |
188 | | * image: display image only |
189 | | * top, bottom, left, right: display image above, below, |
190 | | left of, or right of the text, respectively. |
191 | | * none: the default. display the image if present, |
192 | | otherwise the text. |
193 +--------------+-----------------------------------------------------------+
194 | width | If greater than zero, specifies how much space, in |
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000195 | | character widths, to allocate for the text label; if less |
Guilherme Polocda93aa2009-01-28 13:09:03 +0000196 | | than zero, specifies a minimum width. If zero or |
197 | | unspecified, the natural width of the text label is used. |
198 +--------------+-----------------------------------------------------------+
199
200
201Compatibility Options
202^^^^^^^^^^^^^^^^^^^^^
203
204 +--------+----------------------------------------------------------------+
205 | option | description |
206 +========+================================================================+
207 | state | May be set to "normal" or "disabled" to control the "disabled" |
208 | | state bit. This is a write-only option: setting it changes the |
209 | | widget state, but the :meth:`Widget.state` method does not |
210 | | affect this option. |
211 +--------+----------------------------------------------------------------+
212
213Widget States
214^^^^^^^^^^^^^
215
216The widget state is a bitmap of independent state flags.
217
218 +------------+-------------------------------------------------------------+
219 | flag | description |
220 +============+=============================================================+
221 | active | The mouse cursor is over the widget and pressing a mouse |
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000222 | | button will cause some action to occur. |
Guilherme Polocda93aa2009-01-28 13:09:03 +0000223 +------------+-------------------------------------------------------------+
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000224 | disabled | Widget is disabled under program control. |
Guilherme Polocda93aa2009-01-28 13:09:03 +0000225 +------------+-------------------------------------------------------------+
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000226 | focus | Widget has keyboard focus. |
Guilherme Polocda93aa2009-01-28 13:09:03 +0000227 +------------+-------------------------------------------------------------+
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000228 | pressed | Widget is being pressed. |
Guilherme Polocda93aa2009-01-28 13:09:03 +0000229 +------------+-------------------------------------------------------------+
230 | selected | "On", "true", or "current" for things like Checkbuttons and |
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000231 | | radiobuttons. |
Guilherme Polocda93aa2009-01-28 13:09:03 +0000232 +------------+-------------------------------------------------------------+
233 | background | Windows and Mac have a notion of an "active" or foreground |
234 | | window. The *background* state is set for widgets in a |
235 | | background window, and cleared for those in the foreground |
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000236 | | window. |
Guilherme Polocda93aa2009-01-28 13:09:03 +0000237 +------------+-------------------------------------------------------------+
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000238 | readonly | Widget should not allow user modification. |
Guilherme Polocda93aa2009-01-28 13:09:03 +0000239 +------------+-------------------------------------------------------------+
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000240 | alternate | A widget-specific alternate display format. |
Guilherme Polocda93aa2009-01-28 13:09:03 +0000241 +------------+-------------------------------------------------------------+
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000242 | invalid | The widget's value is invalid. |
Guilherme Polocda93aa2009-01-28 13:09:03 +0000243 +------------+-------------------------------------------------------------+
244
245A state specification is a sequence of state names, optionally prefixed with
246an exclamation point indicating that the bit is off.
247
248
249ttk.Widget
250^^^^^^^^^^
251
252Besides the methods described below, the class :class:`ttk.Widget` supports the
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000253:meth:`Tkinter.Widget.cget` and :meth:`Tkinter.Widget.configure` methods.
Guilherme Polocda93aa2009-01-28 13:09:03 +0000254
255.. class:: Widget
256
257 .. method:: identify(x, y)
258
259 Returns the name of the element at position *x* *y*, or the empty string
260 if the point does not lie within any element.
261
262 *x* and *y* are pixel coordinates relative to the widget.
263
264
265 .. method:: instate(statespec[, callback=None[, *args[, **kw]]])
266
267 Test the widget's state. If a callback is not specified, returns True
268 if the widget state matches *statespec* and False otherwise. If callback
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000269 is specified then it is called with *args* if widget state matches
Guilherme Polocda93aa2009-01-28 13:09:03 +0000270 *statespec*.
271
272
273 .. method:: state([statespec=None])
274
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000275 Modify or read widget state. If *statespec* is specified, sets the
276 widget state accordingly and returns a new *statespec* indicating
Guilherme Polocda93aa2009-01-28 13:09:03 +0000277 which flags were changed. If *statespec* is not specified, returns
278 the currently-enabled state flags.
279
280 *statespec* will usually be a list or a tuple.
281
282
283Combobox
284--------
285
286The :class:`ttk.Combobox` widget combines a text field with a pop-down list of
287values. This widget is a subclass of :class:`Entry`.
288
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000289Besides the methods inherited from :class:`Widget` (:meth:`Widget.cget`,
Guilherme Polocda93aa2009-01-28 13:09:03 +0000290:meth:`Widget.configure`, :meth:`Widget.identify`, :meth:`Widget.instate`
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000291and :meth:`Widget.state`) and those inherited from :class:`Entry`
292(:meth:`Entry.bbox`, :meth:`Entry.delete`, :meth:`Entry.icursor`,
Guilherme Polocda93aa2009-01-28 13:09:03 +0000293:meth:`Entry.index`, :meth:`Entry.inset`, :meth:`Entry.selection`,
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000294:meth:`Entry.xview`), this class has some other methods, described at
Guilherme Polocda93aa2009-01-28 13:09:03 +0000295:class:`ttk.Combobox`.
296
297
298Options
299^^^^^^^
300
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000301This widget accepts the following options:
Guilherme Polocda93aa2009-01-28 13:09:03 +0000302
303 +-----------------+--------------------------------------------------------+
304 | option | description |
305 +=================+========================================================+
306 | exportselection | Boolean value. If set, the widget selection is linked |
307 | | to the Window Manager selection (which can be returned |
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000308 | | by invoking :meth:`Misc.selection_get`, for example). |
Guilherme Polocda93aa2009-01-28 13:09:03 +0000309 +-----------------+--------------------------------------------------------+
310 | justify | Specifies how the text is aligned within the widget. |
311 | | One of "left", "center", or "right". |
312 +-----------------+--------------------------------------------------------+
313 | height | Specifies the height of the pop-down listbox, in rows. |
314 +-----------------+--------------------------------------------------------+
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000315 | postcommand | A script (possibly registered with |
316 | | :meth:`Misc.register`) that |
Guilherme Polocda93aa2009-01-28 13:09:03 +0000317 | | is called immediately before displaying the values. It |
318 | | may specify which values to display. |
319 +-----------------+--------------------------------------------------------+
320 | state | One of "normal", "readonly", or "disabled". In the |
321 | | "readonly" state, the value may not be edited directly,|
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000322 | | and the user can only select one of the values from the|
Guilherme Polocda93aa2009-01-28 13:09:03 +0000323 | | dropdown list. In the "normal" state, the text field is|
324 | | directly editable. In the "disabled" state, no |
325 | | interaction is possible. |
326 +-----------------+--------------------------------------------------------+
327 | textvariable | Specifies a name whose value is linked to the widget |
328 | | value. Whenever the value associated with that name |
329 | | changes, the widget value is updated, and vice versa. |
330 | | See :class:`Tkinter.StringVar`. |
331 +-----------------+--------------------------------------------------------+
332 | values | Specifies the list of values to display in the |
333 | | drop-down listbox. |
334 +-----------------+--------------------------------------------------------+
335 | width | Specifies an integer value indicating the desired width|
336 | | of the entry window, in average-size characters of the |
337 | | widget's font. |
338 +-----------------+--------------------------------------------------------+
339
340
341Virtual events
342^^^^^^^^^^^^^^
343
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000344The combobox widget generates a **<<ComboboxSelected>>** virtual event
Guilherme Polocda93aa2009-01-28 13:09:03 +0000345when the user selects an element from the list of values.
346
347
348ttk.Combobox
349^^^^^^^^^^^^
350
351.. class:: Combobox
352
353 .. method:: current([newindex=None])
354
355 If *newindex* is specified, sets the combobox value to the element
356 position *newindex*. Otherwise, returns the index of the current value or
357 -1 if the current value is not in the values list.
358
359
360 .. method:: get()
361
362 Returns the current value of the combobox.
363
364
365 .. method:: set(value)
366
367 Sets the value of the combobox to *value*.
368
369
370Notebook
371--------
372
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000373The Ttk Notebook widget manages a collection of windows and displays a single
Guilherme Polocda93aa2009-01-28 13:09:03 +0000374one at a time. Each child window is associated with a tab, which the user
375may select to change the currently-displayed window.
376
377
378Options
379^^^^^^^
380
381This widget accepts the following specific options:
382
383 +---------+----------------------------------------------------------------+
384 | option | description |
385 +=========+================================================================+
386 | height | If present and greater than zero, specifies the desired height |
387 | | of the pane area (not including internal padding or tabs). |
388 | | Otherwise, the maximum height of all panes is used. |
389 +---------+----------------------------------------------------------------+
390 | padding | Specifies the amount of extra space to add around the outside |
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000391 | | of the notebook. The padding is a list of up to four length |
392 | | specifications: left top right bottom. If fewer than four |
Guilherme Polocda93aa2009-01-28 13:09:03 +0000393 | | elements are specified, bottom defaults to top, right defaults |
394 | | to left, and top defaults to left. |
395 +---------+----------------------------------------------------------------+
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000396 | width | If present and greater than zero, specifies the desired width |
Guilherme Polocda93aa2009-01-28 13:09:03 +0000397 | | of the pane area (not including internal padding). Otherwise, |
398 | | the maximum width of all panes is used. |
399 +---------+----------------------------------------------------------------+
400
401
402Tab Options
403^^^^^^^^^^^
404
405There are also specific options for tabs:
406
407 +-----------+--------------------------------------------------------------+
408 | option | description |
409 +===========+==============================================================+
410 | state | Either "normal", "disabled" or "hidden". If "disabled", then |
411 | | the tab is not selectable. If "hidden", then the tab is not |
412 | | shown. |
413 +-----------+--------------------------------------------------------------+
414 | sticky | Specifies how the child window is positioned within the pane |
415 | | area. Value is a string containing zero or more of the |
416 | | characters "n", "s", "e" or "w". Each letter refers to a |
417 | | side (north, south, east or west) that the child window will |
418 | | stick to, as per the :meth:`grid` geometry manager. |
419 +-----------+--------------------------------------------------------------+
420 | padding | Specifies the amount of extra space to add between the |
421 | | notebook and this pane. Syntax is the same as for the option |
422 | | padding used by this widget. |
423 +-----------+--------------------------------------------------------------+
424 | text | Specifies a text to be displayed in the tab. |
425 +-----------+--------------------------------------------------------------+
426 | image | Specifies an image to display in the tab. See the option |
427 | | image described in :class:`Widget`. |
428 +-----------+--------------------------------------------------------------+
429 | compound | Specifies how to display the image relative to the text, in |
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000430 | | the case both text and image options are present. See |
Guilherme Polocda93aa2009-01-28 13:09:03 +0000431 | | `Label Options`_ for legal values. |
432 +-----------+--------------------------------------------------------------+
433 | underline | Specifies the index (0-based) of a character to underline in |
434 | | the text string. The underlined character is used for |
435 | | mnemonic activation if :meth:`Notebook.enable_traversal` is |
436 | | called. |
437 +-----------+--------------------------------------------------------------+
438
439
440Tab Identifiers
441^^^^^^^^^^^^^^^
442
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000443The *tab_id* present in several methods of :class:`ttk.Notebook` may take any
Guilherme Polocda93aa2009-01-28 13:09:03 +0000444of the following forms:
445
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000446* An integer between zero and the number of tabs.
447* The name of a child window.
448* A positional specification of the form "@x,y", which identifies the tab.
449* The literal string "current", which identifies the currently-selected tab.
Guilherme Polocda93aa2009-01-28 13:09:03 +0000450* The literal string "end", which returns the number of tabs (only valid for
Andrew M. Kuchling8c2f85c2009-01-31 03:26:02 +0000451 :meth:`Notebook.index`).
Guilherme Polocda93aa2009-01-28 13:09:03 +0000452
453
454Virtual Events
455^^^^^^^^^^^^^^
456
457This widget generates a **<<NotebookTabChanged>>** virtual event after a new
458tab is selected.
459
460
461ttk.Notebook
462^^^^^^^^^^^^
463
464.. class:: Notebook
465
466 .. method:: add(child, **kw)
467
468 Adds a new tab to the notebook.
469
470 If window is currently managed by the notebook but hidden, it is
471 restored to its previous position.
472
473 See `Tab Options`_ for the list of available options.
474
475
476 .. method:: forget(tab_id)
477
478 Removes the tab specified by *tab_id*, unmaps and unmanages the
479 associated window.
480
481
482 .. method:: hide(tab_id)
483
484 Hides the tab specified by *tab_id*.
485
486 The tab will not be displayed, but the associated window remains
487 managed by the notebook and its configuration remembered. Hidden tabs
488 may be restored with the add command.
489
490
491 .. method:: identify(x, y)
492
493 Returns the name of the tab element at position *x*, *y*, or the empty
494 string if none.
495
496
497 .. method:: index(tab_id)
498
499 Returns the numeric index of the tab specified by *tab_id*, or the total
500 number of tabs if *tab_id* is the string "end".
501
502
503 .. method:: insert(pos, child, **kw)
504
505 Inserts a pane at the specified position.
506
507 *pos* is either the string end, an integer index, or the name of a
508 managed child. If *child* is already managed by the notebook, moves it to
509 the specified position.
510
511 See `Tab Options`_ for the list of available options.
512
513
514 .. method:: select([tab_id])
515
516 Selects the specified *tab_id*.
517
518 The associated child window will be displayed, and the
519 previously-selected window (if different) is unmapped. If *tab_id* is
520 omitted, returns the widget name of the currently selected pane.
521
522
523 .. method:: tab(tab_id[, option=None[, **kw]])
524
525 Query or modify the options of the specific *tab_id*.
526
527 If *kw* is not given, returns a dict of the tab option values. If
528 *option* is specified, returns the value of that *option*. Otherwise,
529 sets the options to the corresponding values.
530
531
532 .. method:: tabs()
533
534 Returns a list of windows managed by the notebook.
535
536
537 .. method:: enable_traversal()
538
539 Enable keyboard traversal for a toplevel window containing this notebook.
540
541 This will extend the bindings for the toplevel window containing the
542 notebook as follows:
543
544 * Control-Tab: selects the tab following the currently selected one
545 * Shift-Control-Tab: selects the tab preceding the currently selected one
546 * Alt-K: where K is the mnemonic (underlined) character of any tab, will
547 select that tab.
548
549 Multiple notebooks in a single toplevel may be enabled for traversal,
550 including nested notebooks. However, notebook traversal only works
551 properly if all panes have as master the notebook they are in.
552
553
554Progressbar
555-----------
556
557The :class:`ttk.Progressbar` widget shows the status of a long-running
558operation. It can operate in two modes: determinate mode shows the amount
559completed relative to the total amount of work to be done, and indeterminate
560mode provides an animated display to let the user know that something is
561happening.
562
563
564Options
565^^^^^^^
566
567This widget accepts the following specific options:
568
569 +----------+---------------------------------------------------------------+
570 | option | description |
571 +==========+===============================================================+
572 | orient | One of "horizontal" or "vertical". Specifies the orientation |
573 | | of the progress bar. |
574 +----------+---------------------------------------------------------------+
575 | length | Specifies the length of the long axis of the progress bar |
576 | | (width if horizontal, height if vertical). |
577 +----------+---------------------------------------------------------------+
578 | mode | One of "determinate" or "indeterminate". |
579 +----------+---------------------------------------------------------------+
580 | maximum | A number specifying the maximum value. Defaults to 100. |
581 +----------+---------------------------------------------------------------+
582 | value | The current value of the progress bar. In "determinate" mode, |
583 | | this represents the amount of work completed. In |
584 | | "indeterminate" mode, it is interpreted as modulo maximum; |
585 | | that is, the progress bar completes one "cycle" when its value|
586 | | increases by maximum. |
587 +----------+---------------------------------------------------------------+
588 | variable | A name which is linked to the option value. If specified, the |
589 | | value of the progressbar is automatically set to the value of |
590 | | this name whenever the latter is modified. |
591 +----------+---------------------------------------------------------------+
592 | phase | Read-only option. The widget periodically increments the value|
593 | | of this option whenever its value is greater than 0 and, in |
594 | | determinate mode, less than maximum. This option may be used |
595 | | by the current theme to provide additional animation effects. |
596 +----------+---------------------------------------------------------------+
597
598
599ttk.Progressbar
600^^^^^^^^^^^^^^^
601
602.. class:: Progressbar
603
604 .. method:: start([interval])
605
606 Begin autoincrement mode: schedules a recurring timer even that calls
607 :meth:`Progressbar.step` every *interval* milliseconds. If omitted,
608 *interval* defaults to 50 milliseconds.
609
610
611 .. method:: step([amount])
612
613 Increments progressbar's value by *amount*.
614
615 *amount* defaults to 1.0 if omitted.
616
617
618 .. method:: stop()
619
620 Stop autoincrement mode: cancels any recurring timer event initiated by
621 :meth:`Progressbar.start` for this progressbar.
622
623
624Separator
625---------
626
627The :class:`ttk.Separator` widget displays a horizontal or vertical separator
628bar.
629
630It has no other method besides the ones inherited from :class:`ttk.Widget`.
631
632
633Options
634^^^^^^^
635
636This widget accepts the following specific option:
637
638 +--------+----------------------------------------------------------------+
639 | option | description |
640 +========+================================================================+
641 | orient | One of "horizontal" or "vertical". Specifies the orientation of|
642 | | the separator. |
643 +--------+----------------------------------------------------------------+
644
645
646Sizegrip
647--------
648
649The :class:`ttk.Sizegrip` widget (also known as grow box) allows the user to
650resize the containing toplevel window by pressing and dragging the grip.
651
652This widget has no specific options neither specific methods, besides the
653ones inherited from :class:`ttk.Widget`.
654
655
656Platform-specific notes
657^^^^^^^^^^^^^^^^^^^^^^^
658
659* On Mac OSX, toplevel windows automatically include a built-in size grip
660 by default. Adding a Sizegrip there is harmless, since the built-in
661 grip will just mask the widget.
662
663
664Bugs
665^^^^
666
667* If the containing toplevel's position was specified relative to the right
668 or bottom of the screen (e.g. ....), the Sizegrip widget will not resize
669 the window.
670* This widget supports only "southeast" resizing.
671
672
673Treeview
674--------
675
676The :class:`ttk.Treeview` widget displays a hierarchical collection of items.
677Each item has a textual label, an optional image, and an optional list of data
678values. The data values are displayed in successive columns after the tree
679label.
680
681The order in which data values are displayed may be controlled by setting
682the widget option displaycolumns. The tree widget can also display column
683headings. Columns may be accessed by number or symbolic names listed in the
684widget option columns. See `Column Identifiers`_.
685
686Each item is identified by an unique name. The widget will generate item IDs
687if they are not supplied by the caller. There is a distinguished root item,
688named {}. The root item itself is not displayed; its children appear at the
689top level of the hierarchy.
690
691Each item also has a list of tags, which can be used to associate even bindings
692with individual items and control the appearance of the item.
693
694The Treeview widget supports horizontal and vertical scrolling, according to
695the options described in `Scrollable Widget Options`_ and the methods
696:meth:`Treeview.xview` and :meth:`Treeview.yview`.
697
698
699Options
700^^^^^^^
701
702This widget accepts the following specific option:
703
704 +----------------+--------------------------------------------------------+
705 | option | description |
706 +================+========================================================+
707 | columns | A list of column identifiers, specifying the number of |
708 | | columns and their names. |
709 +----------------+--------------------------------------------------------+
710 | displaycolumns | A list of column identifiers (either symbolic or |
711 | | integer indices) specifying which data columns are |
712 | | displayed and the order in which they appear, or the |
713 | | string "#all". |
714 +----------------+--------------------------------------------------------+
715 | height | Specifies the number of rows which should be visible. |
716 | | Note: the requested width is determined from the sum |
717 | | of the column widths. |
718 +----------------+--------------------------------------------------------+
719 | padding | Specifies the internal padding for the widget. The |
720 | | padding is a list of up to four length specifications. |
721 +----------------+--------------------------------------------------------+
722 | selectmode | Controls how the built-in class bindings manage the |
723 | | selection. One of "extended", "browse" or "none". |
724 | | If set to "extended" (the default), multiple items may |
725 | | be selected. If "browse", only a single item will be |
726 | | selected at a time. If "none", the selection will not |
727 | | be changed. |
728 | | |
729 | | Note that the application code and tag bindings can set|
730 | | the selection however they wish, regardless the value |
731 | | of this option. |
732 +----------------+--------------------------------------------------------+
733 | show | A list containing zero or more of the following values,|
734 | | specifying which elements of the tree to display. |
735 | | |
736 | | * tree: display tree labels in column #0. |
737 | | * headings: display the heading row. |
738 | | |
739 | | The default is "tree headings", i.e., show all |
740 | | elements. |
741 | | |
742 | | **Note**: Column #0 always refer to the tree column, |
743 | | even if show="tree" is not specified. |
744 +----------------+--------------------------------------------------------+
745
746
747Item Options
748^^^^^^^^^^^^
749
750The following item options may be specified for items in the insert and item
751widget commands.
752
753 +--------+---------------------------------------------------------------+
754 | option | description |
755 +========+===============================================================+
756 | text | The textual label to display for the item. |
757 +--------+---------------------------------------------------------------+
758 | image | A Tk Image, displayed to the left of the label. |
759 +--------+---------------------------------------------------------------+
760 | values | The list of values associated with the item. |
761 | | |
762 | | Each item should have the same number of values as the widget |
763 | | option columns. If there are fewer values than columns, the |
764 | | remaining values are assumed empty. If there are more values |
765 | | than columns, the extra values are ignored. |
766 +--------+---------------------------------------------------------------+
767 | open | True/False value indicating whether the item's children should|
768 | | be displayed or hidden. |
769 +--------+---------------------------------------------------------------+
770 | tags | A list of tags associated with this item. |
771 +--------+---------------------------------------------------------------+
772
773
774Tag Options
775^^^^^^^^^^^
776
777The following options may be specified on tags:
778
779 +------------+-----------------------------------------------------------+
780 | option | description |
781 +============+===========================================================+
782 | foreground | Specifies the text foreground color. |
783 +------------+-----------------------------------------------------------+
784 | background | Specifies the cell or item background color. |
785 +------------+-----------------------------------------------------------+
786 | font | Specifies the font to use when drawing text. |
787 +------------+-----------------------------------------------------------+
788 | image | Specifies the item image, in case the item's image option |
789 | | is empty. |
790 +------------+-----------------------------------------------------------+
791
792
793Column Identifiers
794^^^^^^^^^^^^^^^^^^
795
796Column identifiers take any of the following forms:
797
798* A symbolic name from the list of columns option.
799* An integer n, specifying the nth data column.
800* A string of the form #n, where n is an integer, specifying the nth display
801 column.
802
803Notes:
804
805* Item's option values may be displayed in a different order than the order
806 in which they are stored.
807* Column #0 always refers to the tree column, even if show="tree" is not
808 specified.
809
810A data column number is an index into an item's option values list; a display
811column number is the column number in the tree where the values are displayed.
812Tree labels are displayed in column #0. If option displaycolumns is not set,
813then data column n is displayed in column #n+1. Again, **column #0 always
814refers to the tree column**.
815
816
817Virtual Events
818^^^^^^^^^^^^^^
819
820The Treeview widget generates the following virtual events.
821
822 +--------------------+--------------------------------------------------+
823 | event | description |
824 +====================+==================================================+
825 | <<TreeviewSelect>> | Generated whenever the selection changes. |
826 +--------------------+--------------------------------------------------+
827 | <<TreeviewOpen>> | Generated just before settings the focus item to |
828 | | open=True. |
829 +--------------------+--------------------------------------------------+
830 | <<TreeviewClose>> | Generated just after setting the focus item to |
831 | | open=False. |
832 +--------------------+--------------------------------------------------+
833
834The :meth:`Treeview.focus` and :meth:`Treeview.selection` methods can be used
835to determine the affected item or items.
836
837
838ttk.Treeview
839^^^^^^^^^^^^
840
841.. class:: Treeview
842
843 .. method:: bbox(item[, column=None])
844
845 Returns the bounding box (relative to the treeview widget's window) of
846 the specified *item* in the form (x, y, width, height).
847
848 If *column* is specified, returns the bounding box of that cell. If the
849 *item* is not visible (i.e., if it is a descendant of a closed item or is
850 scrolled offscreen), returns an empty string.
851
852
853 .. method:: get_children([item])
854
855 Returns the list of children belonging to *item*.
856
857 If *item* is not specified, returns root children.
858
859
860 .. method:: set_children(item, *newchildren)
861
862 Replaces item's child with *newchildren*.
863
864 Children present in item that are not present in *newchildren* are
865 detached from tree. No items in *newchildren* may be an ancestor of
866 item. Note that not specifying *newchildren* results in detaching
867 *item*'s children.
868
869
870 .. method:: column(column[, option=None[, **kw]])
871
872 Query or modify the options for the specified *column*.
873
874 If *kw* is not given, returns a dict of the column option values. If
875 *option* is specified then the value for that *option* is returned.
876 Otherwise, sets the options to the corresponding values.
877
878 The valid options/values are:
879
880 * id
881 Returns the column name, this is a read-only option.
882 * anchor: One of the standard Tk anchor values.
883 Specifies how the text in this column should be aligned with respect
884 to the cell.
885 * minwidth: width
886 The minimum width of the column in pixels. The treeview widget will
887 not make the column any smaller than the specified by this option when
888 the widget is resized or the user drags a column.
889 * stretch: True/False
890 Specifies wheter or not the column's width should be adjusted when
891 the widget is resized.
892 * width: width
893 The width of the column in pixels.
894
895 To configure the tree column, call this with column = "#0"
896
897 .. method:: delete(*items)
898
899 Delete all specified *items* and all their descendants.
900
901 The root item may not be deleted.
902
903
904 .. method:: detach(*items)
905
906 Unlinks all of the specified *items* from the tree.
907
908 The items and all of their descendants are still present, and may be
909 reinserted at another point in the tree, but will not be displayed.
910
911 The root item may not be detached.
912
913
914 .. method:: exists(item)
915
916 Returns True if the specified *item* is present in the three,
917 False otherwise.
918
919
920 .. method:: focus([item=None])
921
922 If *item* is specified, sets the focus item to *item*. Otherwise, returns
923 the current focus item, or '' if there is none.
924
925
926 .. method:: heading(column[, option=None[, **kw]])
927
928 Query or modify the heading options for the specified *column*.
929
930 If *kw* is not given, returns a dict of the heading option values. If
931 *option* is specified then the value for that *option* is returned.
932 Otherwise, sets the options to the corresponding values.
933
934 The valid options/values are:
935
936 * text: text
937 The text to display in the column heading.
938 * image: imageName
939 Specifies an image to display to the right of the column heading.
940 * anchor: anchor
941 Specifies how the heading text should be aligned. One of the standard
942 Tk anchor values.
943 * command: callback
944 A callback to be invoked when the heading label is pressed.
945
946 To configure the tree column heading, call this with column = "#0"
947
948
949 .. method:: identify(component, x, y)
950
951 Returns a description of the specified *component* under the point given
952 by *x* and *y*, or the empty string if no such *component* is present at
953 that position.
954
955
956 .. method:: identify_row(y)
957
958 Returns the item ID of the item at position *y*.
959
960
961 .. method:: identify_column(x)
962
963 Returns the data column identifier of the cell at position *x*.
964
965 The tree column has ID #0.
966
967
968 .. method:: identify_region(x, y)
969
970 Returns one of:
971
972 +-----------+--------------------------------------+
973 | region | meaning |
974 +===========+======================================+
975 | heading | Tree heading area. |
976 +-----------+--------------------------------------+
977 | separator | Space between two columns headings. |
978 +-----------+--------------------------------------+
979 | tree | The tree area. |
980 +-----------+--------------------------------------+
981 | cell | A data cell. |
982 +-----------+--------------------------------------+
983
984 Availability: Tk 8.6.
985
986
987 .. method:: identify_element(x, y)
988
989 Returns the element at position x, y.
990
991 Availability: Tk 8.6.
992
993
994 .. method:: index(item)
995
996 Returns the integer index of *item* within its parent's list of children.
997
998
999 .. method:: insert(parent, index[, iid=None[, **kw]])
1000
1001 Creates a new item and return the item identifier of the newly created
1002 item.
1003
1004 *parent* is the item ID of the parent item, or the empty string to create
1005 a new top-level item. *index* is an integer, or the value "end",
1006 specifying where in the list of parent's children to insert the new item.
1007 If *index* is less than or equal to zero, the new node is inserted at
1008 the beginning, if *index* is greater than or equal to the current number
1009 of children, it is inserted at the end. If *iid* is specified, it is used
1010 as the item identifier, *iid* must not already exist in the tree.
1011 Otherwise, a new unique identifier is generated.
1012
1013 See `Item Options`_ for the list of available points.
1014
1015
1016 .. method:: item(item[, option[, **kw]])
1017
1018 Query or modify the options for the specified *item*.
1019
1020 If no options are given, a dict with options/values for the item is
1021 returned.
1022 If *option* is specified then the value for that option is returned.
1023 Otherwise, sets the options to the corresponding values as given by *kw*.
1024
1025
1026 .. method:: move(item, parent, index)
1027
1028 Moves *item* to position *index* in *parent*'s list of children.
1029
1030 It is illegal to move an item under one of its descendants. If index is
1031 less than or equal to zero, item is moved to the beginning, if greater
1032 than or equal to the number of children, it is moved to the end. If item
1033 was detached it is reattached.
1034
1035
1036 .. method:: next(item)
1037
1038 Returns the identifier of *item*'s next sibling, or '' if *item* is the
1039 last child of its parent.
1040
1041
1042 .. method:: parent(item)
1043
1044 Returns the ID of the parent of *item*, or '' if *item* is at the top
1045 level of the hierarchy.
1046
1047
1048 .. method:: prev(item)
1049
1050 Returns the identifier of *item*'s previous sibling, or '' if *item* is
1051 the first child of its parent.
1052
1053
1054 .. method:: reattach(item, parent, index)
1055
1056 An alias for :meth:`Treeview.move`.
1057
1058
1059 .. method:: see(item)
1060
1061 Ensure that *item* is visible.
1062
1063 Sets all of *item*'s ancestors open option to True, and scrolls the
1064 widget if necessary so that *item* is within the visible portion of
1065 the tree.
1066
1067
1068 .. method:: selection([selop=None[, items=None]])
1069
1070 If *selop* is not specified, returns selected items. Otherwise, it will
1071 act according to the following selection methods.
1072
1073
1074 .. method:: selection_set(items)
1075
1076 *items* becomes the new selection.
1077
1078
1079 .. method:: selection_add(items)
1080
1081 Add *items* to the selection.
1082
1083
1084 .. method:: selection_remove(items)
1085
1086 Remove *items* from the selection.
1087
1088
1089 .. method:: selection_toggle(items)
1090
1091 Toggle the selection state of each item in *items*.
1092
1093
1094 .. method:: set(item[, column=None[, value=None]])
1095
1096 With one argument, returns a dictionary of column/value pairs for the
1097 specified *item*. With two arguments, returns the current value of the
1098 specified *column*. With three arguments, sets the value of given
1099 *column* in given *item* to the specified *value*.
1100
1101
1102 .. method:: tag_bind(tagname[, sequence=None[, callback=None]])
1103
1104 Bind a callback for the given event *sequence* to the tag *tagname*.
1105 When an event is delivered to an item, the *callbacks* for each of the
1106 item's tags option are called.
1107
1108
1109 .. method:: tag_configure(tagname[, option=None[, **kw]])
1110
1111 Query or modify the options for the specified *tagname*.
1112
1113 If *kw* is not given, returns a dict of the option settings for
1114 *tagname*. If *option* is specified, returns the value for that *option*
1115 for the specified *tagname*. Otherwise, sets the options to the
1116 corresponding values for the given *tagname*.
1117
1118
1119 .. method:: tag_has(tagname[, item])
1120
1121 If *item* is specified, returns 1 or 0 depending on whether the specified
1122 *item* has the given *tagname*. Otherwise, returns a list of all items
1123 which have the specified tag.
1124
1125 Availability: Tk 8.6
1126
1127
1128 .. method:: xview(*args)
1129
1130 Query or modify horizontal position of the treeview.
1131
1132
1133 .. method:: yview(*args)
1134
1135 Query or modify vertical position of the treeview.
1136
1137
1138.. _TtkStyling:
1139
1140Ttk Styling
1141-----------
1142
1143Each widget in :mod:`ttk` is assigned a style, which specifies the set of
Benjamin Peterson288618e2009-03-03 22:51:57 +00001144elements making up the widget and how they are arranged, along with dynamic and
1145default settings for element options. By default the style name is the same as
1146the widget's class name, but it may be overriden by the widget's style
1147option. If the class name of a widget is unkown, use the method
Guilherme Polocda93aa2009-01-28 13:09:03 +00001148:meth:`Misc.winfo_class` (somewidget.winfo_class()).
1149
1150.. seealso::
1151
1152 `Tcl'2004 conference presentation <http://tktable.sourceforge.net/tile/tile-tcl2004.pdf>`_
1153 This document explains how the theme engine works
1154
1155
1156.. class:: Style
1157
1158 This class is used to manipulate the style database.
1159
1160
1161 .. method:: configure(style, query_opt=None, **kw)
1162
1163 Query or sets the default value of the specified option(s) in *style*.
1164
1165 Each key in *kw* is an option and each value is a string identifying
1166 the value for that option.
1167
Benjamin Peterson288618e2009-03-03 22:51:57 +00001168 For example, to change every default button to be a flat button with some
1169 padding and a different background color do::
Guilherme Polocda93aa2009-01-28 13:09:03 +00001170
1171 import ttk
1172 import Tkinter
1173
1174 root = Tkinter.Tk()
1175
1176 ttk.Style().configure("TButton", padding=6, relief="flat",
1177 background="#ccc")
1178
1179 btn = ttk.Button(text="Sample")
1180 btn.pack()
1181
1182 root.mainloop()
1183
1184
1185 .. method:: map(style, query_opt=None, **kw)
1186
1187 Query or sets dynamic values of the specified option(s) in *style*.
1188
1189 Each key in kw is an option and each value should be a list or a
1190 tuple (usually) containing statespecs grouped in tuples, or list, or
1191 something else of your preference. A statespec is compound of one or more
1192 states and then a value.
1193
Benjamin Peterson288618e2009-03-03 22:51:57 +00001194 An example::
Guilherme Polocda93aa2009-01-28 13:09:03 +00001195
1196 import Tkinter
1197 import ttk
1198
1199 root = Tkinter.Tk()
1200
1201 style = ttk.Style()
1202 style.map("C.TButton",
1203 foreground=[('pressed', 'red'), ('active', 'blue')],
1204 background=[('pressed', '!disabled', 'black'), ('active', 'white')]
1205 )
1206
1207 colored_btn = ttk.Button(text="Test", style="C.TButton").pack()
1208
1209 root.mainloop()
1210
1211
1212 There is a thing to note in this previous short example:
1213
1214 * The order of the (states, value) sequences for an option does matter,
Benjamin Peterson288618e2009-03-03 22:51:57 +00001215 if the order was changed to [('active', 'blue'), ('pressed', 'red')] in
1216 the foreground option, for example, the style would be a blue
1217 foreground when the widget was in active or pressed states.
Guilherme Polocda93aa2009-01-28 13:09:03 +00001218
1219
1220 .. method:: lookup(style, option[, state=None[, default=None]])
1221
1222 Returns the value specified for *option* in *style*.
1223
1224 If *state* is specified, it is expected to be a sequence of one or more
1225 states. If the *default* argument is set, it is used as a fallback value
1226 in case no specification for option is found.
1227
Benjamin Peterson288618e2009-03-03 22:51:57 +00001228 To check what font a Button uses by default, do::
Guilherme Polocda93aa2009-01-28 13:09:03 +00001229
1230 import ttk
1231
1232 print ttk.Style().lookup("TButton", "font")
1233
1234
1235 .. method:: layout(style[, layoutspec=None])
1236
1237 Define the widget layout for given *style*. If *layoutspec* is omitted,
1238 return the layout specification for given style.
1239
1240 *layoutspec*, if specified, is expected to be a list, or some other
1241 sequence type (excluding string), where each item should be a tuple and
1242 the first item is the layout name and the second item should have the
1243 format described described in `Layouts`_.
1244
1245 To understand the format, check this example below (it is not intended
1246 to do anything useful)::
1247
1248 import ttk
1249 import Tkinter
1250
1251 root = Tkinter.Tk()
1252
1253 style = ttk.Style()
1254 style.layout("TMenubutton", [
1255 ("Menubutton.background", None),
1256 ("Menubutton.button", {"children":
1257 [("Menubutton.focus", {"children":
1258 [("Menubutton.padding", {"children":
1259 [("Menubutton.label", {"side": "left", "expand": 1})]
1260 })]
1261 })]
1262 }),
1263 ])
1264
1265 mbtn = ttk.Menubutton(text='Text')
1266 mbtn.pack()
1267 root.mainloop()
1268
1269
1270 .. method:: element_create(elementname, etype, *args, **kw)
1271
1272 Create a new element in the current theme of given *etype* which is
1273 expected to be either "image", "from" or "vsapi". The latter is only
1274 available in Tk 8.6a for Windows XP and Vista and is not described here.
1275
1276 If "image" is used, *args* should contain the default image name followed
1277 by statespec/value pairs (this is the imagespec), *kw* may have the
1278 following options:
1279
1280 * border=padding
1281 padding is a list of up to four integers, specifying the left, top,
1282 right, and bottom borders, respectively.
1283
1284 * height=height
1285 Specifies a minimum height for the element. If less than zero, the
1286 base image's height is used as a default.
1287
1288 * padding=padding
1289 Specifies the element's interior padding. Defaults to border's value
1290 if not specified.
1291
1292 * sticky=spec
1293 Specifies how the image is placed within the final parcel. spec
1294 contains zero or more characters “n”, “s”, “w”, or “e”.
1295
1296 * width=width
1297 Specifies a minimum width for the element. If less than zero, the
1298 base image's width is used as a default.
1299
1300 But if "from" is used, then :meth:`element_create` will clone an existing
1301 element. *args* is expected to contain a themename, which is from where
1302 the element will be cloned, and optionally an element to clone from.
1303 If this element to clone from is not specified, an empty element will
1304 be used. *kw* is discarded here.
1305
1306
1307 .. method:: element_names()
1308
1309 Returns the list of elements defined in the current theme.
1310
1311
1312 .. method:: element_options(elementname)
1313
1314 Returns the list of *elementname*'s options.
1315
1316
1317 .. method:: theme_create(themename[, parent=None[, settings=None]])
1318
1319 Create a new theme.
1320
1321 It is an error if *themename* already exists. If *parent* is specified,
1322 the new theme will inherit styles, elements and layouts from the parent
1323 theme. If *settings* are present they are expected to have the same
1324 syntax used for :meth:`theme_settings`.
1325
1326
1327 .. method:: theme_settings(themename, settings)
1328
1329 Temporarily sets the current theme to *themename*, apply specified
1330 *settings* and then restore the previous theme.
1331
1332 Each key in *settings* is a style and each value may contain the keys
1333 'configure', 'map', 'layout' and 'element create' and they are expected
1334 to have the same format as specified by the methods
1335 :meth:`Style.configure`, :meth:`Style.map`, :meth:`Style.layout` and
1336 :meth:`Style.element_create` respectively.
1337
1338 As an example, lets change the Combobox for the default theme a bit::
1339
1340 import ttk
1341 import Tkinter
1342
1343 root = Tkinter.Tk()
1344
1345 style = ttk.Style()
1346 style.theme_settings("default", {
1347 "TCombobox": {
1348 "configure": {"padding": 5},
1349 "map": {
1350 "background": [("active", "green2"),
1351 ("!disabled", "green4")],
1352 "fieldbackground": [("!disabled", "green3")],
1353 "foreground": [("focus", "OliveDrab1"),
1354 ("!disabled", "OliveDrab2")]
1355 }
1356 }
1357 })
1358
1359 combo = ttk.Combobox().pack()
1360
1361 root.mainloop()
1362
1363
1364 .. method:: theme_names()
1365
1366 Returns a list of all known themes.
1367
1368
1369 .. method:: theme_use([themename])
1370
1371 If *themename* is not given, returns the theme in use, otherwise, set
1372 the current theme to *themename*, refreshes all widgets and emits a
1373 <<ThemeChanged>> event.
1374
1375
1376Layouts
1377^^^^^^^
1378
1379A layout can be just None, if takes no options, or a dict of options specifying
1380how to arrange the element. The layout mechanism uses a simplified
1381version of the pack geometry manager: given an initial cavity, each element is
1382allocated a parcel. Valid options/values are:
1383
1384 * side: whichside
1385 Specifies which side of the cavity to place the the element; one of
1386 top, right, bottom or left. If omitted, the element occupies the
1387 entire cavity.
1388
1389 * sticky: nswe
1390 Specifies where the element is placed inside its allocated parcel.
1391
1392 * unit: 0 or 1
1393 If set to 1, causes the element and all of its descendants to be treated as
1394 a single element for the purposes of :meth:`Widget.identify` et al. It's
1395 used for things like scrollbar thumbs with grips.
1396
1397 * children: [sublayout... ]
1398 Specifies a list of elements to place inside the element. Each
1399 element is a tuple (or other sequence type) where the first item is
1400 the layout name, and the other is a `Layout`_.
1401
1402.. _Layout: `Layouts`_