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