blob: 4efdfac8a98b9843a7d973e9a4d68da58a84beb8 [file] [log] [blame]
Guilherme Polo5f238482009-01-28 14:41:10 +00001:mod:`tkinter.ttk` --- Tk themed widgets
2========================================
3
4.. module:: tkinter.ttk
5 :synopsis: Tk themed widget set
6.. sectionauthor:: Guilherme Polo <ggpolo@gmail.com>
7
8
9.. index:: single: ttk
10
11The :mod:`tkinter.ttk` module provides access to the Tk themed widget set,
Raymond Hettinger238018c2009-04-08 08:23:44 +000012introduced in Tk 8.5. If Python has not been compiled against Tk 8.5, this
13module can still be accessed if *Tile* has been installed. The former
14method using Tk 8.5 provides additional benefits including anti-aliased font
15rendering under X11 and window transparency (requiring a composition
16window manager on X11).
Guilherme Polo5f238482009-01-28 14:41:10 +000017
Raymond Hettinger238018c2009-04-08 08:23:44 +000018The basic idea for :mod:`tkinter.ttk` is to separate, to the extent possible,
Guilherme Polo5f238482009-01-28 14:41:10 +000019the code implementing a widget's behavior from the code implementing its
20appearance.
21
22
23.. seealso::
24
25 `Tk Widget Styling Support <http://www.tcl.tk/cgi-bin/tct/tip/48>`_
Raymond Hettinger238018c2009-04-08 08:23:44 +000026 A document introducing theming support for Tk
Guilherme Polo5f238482009-01-28 14:41:10 +000027
28
29Using Ttk
30---------
31
Raymond Hettinger238018c2009-04-08 08:23:44 +000032To start using Ttk, import its module::
Guilherme Polo5f238482009-01-28 14:41:10 +000033
34 from tkinter import ttk
35
Raymond Hettinger238018c2009-04-08 08:23:44 +000036To override the basic Tk widgets, the import should follow the Tk import::
Guilherme Polo5f238482009-01-28 14:41:10 +000037
38 from tkinter import *
39 from tkinter.ttk import *
40
Raymond Hettinger238018c2009-04-08 08:23:44 +000041That code causes several :mod:`tkinter.ttk` widgets (:class:`Button`,
Guilherme Polo5f238482009-01-28 14:41:10 +000042:class:`Checkbutton`, :class:`Entry`, :class:`Frame`, :class:`Label`,
43:class:`LabelFrame`, :class:`Menubutton`, :class:`PanedWindow`,
Raymond Hettinger238018c2009-04-08 08:23:44 +000044:class:`Radiobutton`, :class:`Scale` and :class:`Scrollbar`) to
45automatically replace the Tk widgets.
Guilherme Polo5f238482009-01-28 14:41:10 +000046
Raymond Hettinger238018c2009-04-08 08:23:44 +000047This has the direct benefit of using the new widgets which gives a better
48look and feel across platforms; however, the replacement widgets are not
49completely compatible. The main difference is that widget options such as
50"fg", "bg" and others related to widget styling are no
51longer present in Ttk widgets. Instead, use the :class:`ttk.Style` class
52for improved styling effects.
53
Guilherme Polo5f238482009-01-28 14:41:10 +000054
55.. seealso::
56
Raymond Hettinger238018c2009-04-08 08:23:44 +000057 `Converting existing applications to use Tile widgets <http://tktable.sourceforge.net/tile/doc/converting.txt>`_
58 A monograph (using Tcl terminology) about differences typically
59 encountered when moving applications to use the new widgets.
Guilherme Polo5f238482009-01-28 14:41:10 +000060
61
62Ttk Widgets
63-----------
64
Raymond Hettinger238018c2009-04-08 08:23:44 +000065Ttk comes with 17 widgets, eleven of which already existed in tkinter:
Guilherme Polo5f238482009-01-28 14:41:10 +000066:class:`Button`, :class:`Checkbutton`, :class:`Entry`, :class:`Frame`,
67:class:`Label`, :class:`LabelFrame`, :class:`Menubutton`, :class:`PanedWindow`,
Raymond Hettinger238018c2009-04-08 08:23:44 +000068:class:`Radiobutton`, :class:`Scale` and :class:`Scrollbar`. The other six are
Guilherme Polo5f238482009-01-28 14:41:10 +000069new: :class:`Combobox`, :class:`Notebook`, :class:`Progressbar`,
70:class:`Separator`, :class:`Sizegrip` and :class:`Treeview`. And all them are
71subclasses of :class:`Widget`.
72
Raymond Hettinger238018c2009-04-08 08:23:44 +000073Using the Ttk widgets gives the application an improved look and feel.
74As discussed above, there are differences in how the styling is coded.
Guilherme Polo5f238482009-01-28 14:41:10 +000075
76Tk code::
77
78 l1 = tkinter.Label(text="Test", fg="black", bg="white")
79 l2 = tkinter.Label(text="Test", fg="black", bg="white")
80
81
82Ttk code::
83
84 style = ttk.Style()
85 style.configure("BW.TLabel", foreground="black", background="white")
86
87 l1 = ttk.Label(text="Test", style="BW.TLabel")
88 l2 = ttk.Label(text="Test", style="BW.TLabel")
89
Raymond Hettinger238018c2009-04-08 08:23:44 +000090For more information about TtkStyling_, see the :class:`Style` class
Guilherme Polo5f238482009-01-28 14:41:10 +000091documentation.
92
93Widget
94------
95
96:class:`ttk.Widget` defines standard options and methods supported by Tk
97themed widgets and is not supposed to be directly instantiated.
98
99
100Standard Options
101^^^^^^^^^^^^^^^^
102
103All the :mod:`ttk` Widgets accepts the following options:
104
Georg Brandl44ea77b2013-03-28 13:28:44 +0100105 .. tabularcolumns:: |l|L|
106
Guilherme Polo5f238482009-01-28 14:41:10 +0000107 +-----------+--------------------------------------------------------------+
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 |
Martin Panterd21e0b52015-10-10 10:36:22 +0000113 | | the widget's default layout and style. This option is |
114 | | read-only, and may only be specified when the window is |
115 | | created. |
Guilherme Polo5f238482009-01-28 14:41:10 +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 |
119 | | for the parent widget. |
120 +-----------+--------------------------------------------------------------+
121 | takefocus | Determines whether the window accepts the focus during |
Ezio Melotti1a263ad2010-03-14 09:51:37 +0000122 | | keyboard traversal. 0, 1 or an empty string is returned. |
123 | | If 0 is returned, it means that the window should be skipped |
124 | | entirely during keyboard traversal. If 1, it means that the |
125 | | window should receive the input focus as long as it is |
126 | | viewable. And an empty string means that the traversal |
127 | | scripts make the decision about whether or not to focus |
128 | | on the window. |
Guilherme Polo5f238482009-01-28 14:41:10 +0000129 +-----------+--------------------------------------------------------------+
130 | style | May be used to specify a custom widget style. |
131 +-----------+--------------------------------------------------------------+
132
133
134Scrollable Widget Options
135^^^^^^^^^^^^^^^^^^^^^^^^^
136
137The following options are supported by widgets that are controlled by a
138scrollbar.
139
Georg Brandl44ea77b2013-03-28 13:28:44 +0100140 .. tabularcolumns:: |l|L|
141
Guilherme Polo5f238482009-01-28 14:41:10 +0000142 +----------------+---------------------------------------------------------+
Georg Brandl44ea77b2013-03-28 13:28:44 +0100143 | Option | Description |
Guilherme Polo5f238482009-01-28 14:41:10 +0000144 +================+=========================================================+
Georg Brandlae2dbe22009-03-13 19:04:40 +0000145 | xscrollcommand | Used to communicate with horizontal scrollbars. |
Guilherme Polo5f238482009-01-28 14:41:10 +0000146 | | |
147 | | When the view in the widget's window change, the widget |
148 | | will generate a Tcl command based on the scrollcommand. |
149 | | |
150 | | Usually this option consists of the method |
151 | | :meth:`Scrollbar.set` of some scrollbar. This will cause|
152 | | the scrollbar to be updated whenever the view in the |
153 | | window changes. |
154 +----------------+---------------------------------------------------------+
Georg Brandlae2dbe22009-03-13 19:04:40 +0000155 | yscrollcommand | Used to communicate with vertical scrollbars. |
Guilherme Polo5f238482009-01-28 14:41:10 +0000156 | | For some more information, see above. |
157 +----------------+---------------------------------------------------------+
158
159
160Label Options
161^^^^^^^^^^^^^
162
163The following options are supported by labels, buttons and other button-like
164widgets.
165
Georg Brandl44ea77b2013-03-28 13:28:44 +0100166 .. tabularcolumns:: |l|p{0.7\linewidth}|
Georg Brandl2c860042009-06-16 19:24:38 +0000167
Guilherme Polo5f238482009-01-28 14:41:10 +0000168 +--------------+-----------------------------------------------------------+
Georg Brandl44ea77b2013-03-28 13:28:44 +0100169 | Option | Description |
Guilherme Polo5f238482009-01-28 14:41:10 +0000170 +==============+===========================================================+
171 | text | Specifies a text string to be displayed inside the widget.|
172 +--------------+-----------------------------------------------------------+
173 | textvariable | Specifies a name whose value will be used in place of the |
174 | | text option resource. |
175 +--------------+-----------------------------------------------------------+
176 | underline | If set, specifies the index (0-based) of a character to |
177 | | underline in the text string. The underline character is |
178 | | used for mnemonic activation. |
179 +--------------+-----------------------------------------------------------+
180 | image | Specifies an image to display. This is a list of 1 or more|
181 | | elements. The first element is the default image name. The|
182 | | rest of the list if a sequence of statespec/value pairs as|
183 | | defined by :meth:`Style.map`, specifying different images |
184 | | to use when the widget is in a particular state or a |
185 | | combination of states. All images in the list should have |
186 | | the same size. |
187 +--------------+-----------------------------------------------------------+
188 | compound | Specifies how to display the image relative to the text, |
189 | | in the case both text and images options are present. |
190 | | Valid values are: |
191 | | |
192 | | * text: display text only |
193 | | * image: display image only |
194 | | * top, bottom, left, right: display image above, below, |
195 | | left of, or right of the text, respectively. |
196 | | * none: the default. display the image if present, |
197 | | otherwise the text. |
198 +--------------+-----------------------------------------------------------+
199 | width | If greater than zero, specifies how much space, in |
200 | | character widths, to allocate for the text label, if less |
201 | | than zero, specifies a minimum width. If zero or |
202 | | unspecified, the natural width of the text label is used. |
203 +--------------+-----------------------------------------------------------+
204
205
206Compatibility Options
207^^^^^^^^^^^^^^^^^^^^^
208
Georg Brandl44ea77b2013-03-28 13:28:44 +0100209 .. tabularcolumns:: |l|L|
210
Guilherme Polo5f238482009-01-28 14:41:10 +0000211 +--------+----------------------------------------------------------------+
Georg Brandl44ea77b2013-03-28 13:28:44 +0100212 | Option | Description |
Guilherme Polo5f238482009-01-28 14:41:10 +0000213 +========+================================================================+
214 | state | May be set to "normal" or "disabled" to control the "disabled" |
215 | | state bit. This is a write-only option: setting it changes the |
216 | | widget state, but the :meth:`Widget.state` method does not |
217 | | affect this option. |
218 +--------+----------------------------------------------------------------+
219
220Widget States
221^^^^^^^^^^^^^
222
223The widget state is a bitmap of independent state flags.
224
Georg Brandl44ea77b2013-03-28 13:28:44 +0100225 .. tabularcolumns:: |l|L|
226
Guilherme Polo5f238482009-01-28 14:41:10 +0000227 +------------+-------------------------------------------------------------+
Georg Brandl44ea77b2013-03-28 13:28:44 +0100228 | Flag | Description |
Guilherme Polo5f238482009-01-28 14:41:10 +0000229 +============+=============================================================+
230 | active | The mouse cursor is over the widget and pressing a mouse |
231 | | button will cause some action to occur |
232 +------------+-------------------------------------------------------------+
233 | disabled | Widget is disabled under program control |
234 +------------+-------------------------------------------------------------+
235 | focus | Widget has keyboard focus |
236 +------------+-------------------------------------------------------------+
237 | pressed | Widget is being pressed |
238 +------------+-------------------------------------------------------------+
239 | selected | "On", "true", or "current" for things like Checkbuttons and |
240 | | radiobuttons |
241 +------------+-------------------------------------------------------------+
242 | background | Windows and Mac have a notion of an "active" or foreground |
243 | | window. The *background* state is set for widgets in a |
244 | | background window, and cleared for those in the foreground |
245 | | window |
246 +------------+-------------------------------------------------------------+
247 | readonly | Widget should not allow user modification |
248 +------------+-------------------------------------------------------------+
249 | alternate | A widget-specific alternate display format |
250 +------------+-------------------------------------------------------------+
251 | invalid | The widget's value is invalid |
252 +------------+-------------------------------------------------------------+
253
254A state specification is a sequence of state names, optionally prefixed with
255an exclamation point indicating that the bit is off.
256
257
258ttk.Widget
259^^^^^^^^^^
260
Benjamin Petersond23f8222009-04-05 19:13:16 +0000261Besides the methods described below, the :class:`ttk.Widget` supports the
Guilherme Polo5f238482009-01-28 14:41:10 +0000262methods :meth:`tkinter.Widget.cget` and :meth:`tkinter.Widget.configure`.
263
264.. class:: Widget
265
266 .. method:: identify(x, y)
267
268 Returns the name of the element at position *x* *y*, or the empty string
269 if the point does not lie within any element.
270
271 *x* and *y* are pixel coordinates relative to the widget.
272
273
Georg Brandl7f01a132009-09-16 15:58:14 +0000274 .. method:: instate(statespec, callback=None, *args, **kw)
Guilherme Polo5f238482009-01-28 14:41:10 +0000275
Serhiy Storchakafbc1c262013-11-29 12:17:13 +0200276 Test the widget's state. If a callback is not specified, returns ``True``
277 if the widget state matches *statespec* and ``False`` otherwise. If callback
Guilherme Polo5f238482009-01-28 14:41:10 +0000278 is specified then it is called with args if widget state matches
279 *statespec*.
280
281
Georg Brandl7f01a132009-09-16 15:58:14 +0000282 .. method:: state(statespec=None)
Guilherme Polo5f238482009-01-28 14:41:10 +0000283
284 Modify or inquire widget state. If *statespec* is specified, sets the
285 widget state according to it and return a new *statespec* indicating
286 which flags were changed. If *statespec* is not specified, returns
287 the currently-enabled state flags.
288
289 *statespec* will usually be a list or a tuple.
290
291
292Combobox
293--------
294
295The :class:`ttk.Combobox` widget combines a text field with a pop-down list of
296values. This widget is a subclass of :class:`Entry`.
297
298Besides the methods inherited from :class:`Widget`: :meth:`Widget.cget`,
299:meth:`Widget.configure`, :meth:`Widget.identify`, :meth:`Widget.instate`
300and :meth:`Widget.state`, and the following inherited from :class:`Entry`:
301:meth:`Entry.bbox`, :meth:`Entry.delete`, :meth:`Entry.icursor`,
Martin Panter96a4f072016-02-10 01:17:51 +0000302:meth:`Entry.index`, :meth:`Entry.insert`, :meth:`Entry.selection`,
Guilherme Polo5f238482009-01-28 14:41:10 +0000303:meth:`Entry.xview`, it has some other methods, described at
304:class:`ttk.Combobox`.
305
306
307Options
308^^^^^^^
309
310This widget accepts the following specific options:
311
Georg Brandl44ea77b2013-03-28 13:28:44 +0100312 .. tabularcolumns:: |l|L|
313
Guilherme Polo5f238482009-01-28 14:41:10 +0000314 +-----------------+--------------------------------------------------------+
Georg Brandl44ea77b2013-03-28 13:28:44 +0100315 | Option | Description |
Guilherme Polo5f238482009-01-28 14:41:10 +0000316 +=================+========================================================+
317 | exportselection | Boolean value. If set, the widget selection is linked |
318 | | to the Window Manager selection (which can be returned |
319 | | by invoking Misc.selection_get, for example). |
320 +-----------------+--------------------------------------------------------+
321 | justify | Specifies how the text is aligned within the widget. |
322 | | One of "left", "center", or "right". |
323 +-----------------+--------------------------------------------------------+
324 | height | Specifies the height of the pop-down listbox, in rows. |
325 +-----------------+--------------------------------------------------------+
326 | postcommand | A script (possibly registered with Misc.register) that |
327 | | is called immediately before displaying the values. It |
328 | | may specify which values to display. |
329 +-----------------+--------------------------------------------------------+
330 | state | One of "normal", "readonly", or "disabled". In the |
331 | | "readonly" state, the value may not be edited directly,|
332 | | and the user can only selection of the values from the |
333 | | dropdown list. In the "normal" state, the text field is|
334 | | directly editable. In the "disabled" state, no |
335 | | interaction is possible. |
336 +-----------------+--------------------------------------------------------+
337 | textvariable | Specifies a name whose value is linked to the widget |
338 | | value. Whenever the value associated with that name |
339 | | changes, the widget value is updated, and vice versa. |
340 | | See :class:`tkinter.StringVar`. |
341 +-----------------+--------------------------------------------------------+
342 | values | Specifies the list of values to display in the |
343 | | drop-down listbox. |
344 +-----------------+--------------------------------------------------------+
345 | width | Specifies an integer value indicating the desired width|
346 | | of the entry window, in average-size characters of the |
347 | | widget's font. |
348 +-----------------+--------------------------------------------------------+
349
350
351Virtual events
352^^^^^^^^^^^^^^
353
354The combobox widgets generates a **<<ComboboxSelected>>** virtual event
355when the user selects an element from the list of values.
356
357
358ttk.Combobox
359^^^^^^^^^^^^
360
361.. class:: Combobox
362
Georg Brandl7f01a132009-09-16 15:58:14 +0000363 .. method:: current(newindex=None)
Guilherme Polo5f238482009-01-28 14:41:10 +0000364
365 If *newindex* is specified, sets the combobox value to the element
366 position *newindex*. Otherwise, returns the index of the current value or
367 -1 if the current value is not in the values list.
368
369
370 .. method:: get()
371
372 Returns the current value of the combobox.
373
374
375 .. method:: set(value)
376
377 Sets the value of the combobox to *value*.
378
379
380Notebook
381--------
382
383Ttk Notebook widget manages a collection of windows and displays a single
384one at a time. Each child window is associated with a tab, which the user
385may select to change the currently-displayed window.
386
387
388Options
389^^^^^^^
390
391This widget accepts the following specific options:
392
Georg Brandl44ea77b2013-03-28 13:28:44 +0100393 .. tabularcolumns:: |l|L|
394
Guilherme Polo5f238482009-01-28 14:41:10 +0000395 +---------+----------------------------------------------------------------+
Georg Brandl44ea77b2013-03-28 13:28:44 +0100396 | Option | Description |
Guilherme Polo5f238482009-01-28 14:41:10 +0000397 +=========+================================================================+
398 | height | If present and greater than zero, specifies the desired height |
399 | | of the pane area (not including internal padding or tabs). |
400 | | Otherwise, the maximum height of all panes is used. |
401 +---------+----------------------------------------------------------------+
402 | padding | Specifies the amount of extra space to add around the outside |
403 | | of the notebook. The padding is a list up to four length |
404 | | specifications left top right bottom. If fewer than four |
405 | | elements are specified, bottom defaults to top, right defaults |
406 | | to left, and top defaults to left. |
407 +---------+----------------------------------------------------------------+
408 | width | If present and greater than zero, specified the desired width |
409 | | of the pane area (not including internal padding). Otherwise, |
410 | | the maximum width of all panes is used. |
411 +---------+----------------------------------------------------------------+
412
413
414Tab Options
415^^^^^^^^^^^
416
417There are also specific options for tabs:
418
Georg Brandl44ea77b2013-03-28 13:28:44 +0100419 .. tabularcolumns:: |l|L|
420
Guilherme Polo5f238482009-01-28 14:41:10 +0000421 +-----------+--------------------------------------------------------------+
Georg Brandl44ea77b2013-03-28 13:28:44 +0100422 | Option | Description |
Guilherme Polo5f238482009-01-28 14:41:10 +0000423 +===========+==============================================================+
424 | state | Either "normal", "disabled" or "hidden". If "disabled", then |
425 | | the tab is not selectable. If "hidden", then the tab is not |
426 | | shown. |
427 +-----------+--------------------------------------------------------------+
428 | sticky | Specifies how the child window is positioned within the pane |
429 | | area. Value is a string containing zero or more of the |
430 | | characters "n", "s", "e" or "w". Each letter refers to a |
431 | | side (north, south, east or west) that the child window will |
432 | | stick to, as per the :meth:`grid` geometry manager. |
433 +-----------+--------------------------------------------------------------+
434 | padding | Specifies the amount of extra space to add between the |
435 | | notebook and this pane. Syntax is the same as for the option |
436 | | padding used by this widget. |
437 +-----------+--------------------------------------------------------------+
438 | text | Specifies a text to be displayed in the tab. |
439 +-----------+--------------------------------------------------------------+
440 | image | Specifies an image to display in the tab. See the option |
441 | | image described in :class:`Widget`. |
442 +-----------+--------------------------------------------------------------+
443 | compound | Specifies how to display the image relative to the text, in |
444 | | the case both options text and image are present. See |
445 | | `Label Options`_ for legal values. |
446 +-----------+--------------------------------------------------------------+
447 | underline | Specifies the index (0-based) of a character to underline in |
448 | | the text string. The underlined character is used for |
449 | | mnemonic activation if :meth:`Notebook.enable_traversal` is |
450 | | called. |
451 +-----------+--------------------------------------------------------------+
452
453
454Tab Identifiers
455^^^^^^^^^^^^^^^
456
457The tab_id present in several methods of :class:`ttk.Notebook` may take any
458of the following forms:
459
460* An integer between zero and the number of tabs
461* The name of a child window
462* A positional specification of the form "@x,y", which identifies the tab
463* The literal string "current", which identifies the currently-selected tab
464* The literal string "end", which returns the number of tabs (only valid for
465 :meth:`Notebook.index`)
466
467
468Virtual Events
469^^^^^^^^^^^^^^
470
471This widget generates a **<<NotebookTabChanged>>** virtual event after a new
472tab is selected.
473
474
475ttk.Notebook
476^^^^^^^^^^^^
477
478.. class:: Notebook
479
480 .. method:: add(child, **kw)
481
482 Adds a new tab to the notebook.
483
484 If window is currently managed by the notebook but hidden, it is
485 restored to its previous position.
486
487 See `Tab Options`_ for the list of available options.
488
489
490 .. method:: forget(tab_id)
491
492 Removes the tab specified by *tab_id*, unmaps and unmanages the
493 associated window.
494
495
496 .. method:: hide(tab_id)
497
498 Hides the tab specified by *tab_id*.
499
500 The tab will not be displayed, but the associated window remains
501 managed by the notebook and its configuration remembered. Hidden tabs
Benjamin Petersond23f8222009-04-05 19:13:16 +0000502 may be restored with the :meth:`add` command.
Guilherme Polo5f238482009-01-28 14:41:10 +0000503
504
505 .. method:: identify(x, y)
506
507 Returns the name of the tab element at position *x*, *y*, or the empty
508 string if none.
509
510
511 .. method:: index(tab_id)
512
513 Returns the numeric index of the tab specified by *tab_id*, or the total
514 number of tabs if *tab_id* is the string "end".
515
516
517 .. method:: insert(pos, child, **kw)
518
519 Inserts a pane at the specified position.
520
Benjamin Petersond23f8222009-04-05 19:13:16 +0000521 *pos* is either the string "end", an integer index, or the name of a
Guilherme Polo5f238482009-01-28 14:41:10 +0000522 managed child. If *child* is already managed by the notebook, moves it to
523 the specified position.
524
525 See `Tab Options`_ for the list of available options.
526
527
Georg Brandl7f01a132009-09-16 15:58:14 +0000528 .. method:: select(tab_id=None)
Guilherme Polo5f238482009-01-28 14:41:10 +0000529
530 Selects the specified *tab_id*.
531
532 The associated child window will be displayed, and the
533 previously-selected window (if different) is unmapped. If *tab_id* is
534 omitted, returns the widget name of the currently selected pane.
535
536
Georg Brandl7f01a132009-09-16 15:58:14 +0000537 .. method:: tab(tab_id, option=None, **kw)
Guilherme Polo5f238482009-01-28 14:41:10 +0000538
539 Query or modify the options of the specific *tab_id*.
540
Benjamin Petersond23f8222009-04-05 19:13:16 +0000541 If *kw* is not given, returns a dictionary of the tab option values. If
Guilherme Polo5f238482009-01-28 14:41:10 +0000542 *option* is specified, returns the value of that *option*. Otherwise,
543 sets the options to the corresponding values.
544
545
546 .. method:: tabs()
547
548 Returns a list of windows managed by the notebook.
549
550
551 .. method:: enable_traversal()
552
553 Enable keyboard traversal for a toplevel window containing this notebook.
554
555 This will extend the bindings for the toplevel window containing the
556 notebook as follows:
557
Serhiy Storchaka0424eaf2015-09-12 17:45:25 +0300558 * :kbd:`Control-Tab`: selects the tab following the currently selected one.
559 * :kbd:`Shift-Control-Tab`: selects the tab preceding the currently selected one.
560 * :kbd:`Alt-K`: where *K* is the mnemonic (underlined) character of any tab, will
Guilherme Polo5f238482009-01-28 14:41:10 +0000561 select that tab.
562
563 Multiple notebooks in a single toplevel may be enabled for traversal,
564 including nested notebooks. However, notebook traversal only works
Benjamin Petersond23f8222009-04-05 19:13:16 +0000565 properly if all panes have the notebook they are in as master.
Guilherme Polo5f238482009-01-28 14:41:10 +0000566
567
568Progressbar
569-----------
570
571The :class:`ttk.Progressbar` widget shows the status of a long-running
Raymond Hettinger238018c2009-04-08 08:23:44 +0000572operation. It can operate in two modes: 1) the determinate mode which shows the
573amount completed relative to the total amount of work to be done and 2) the
574indeterminate mode which provides an animated display to let the user know that
575work is progressing.
Guilherme Polo5f238482009-01-28 14:41:10 +0000576
577
578Options
579^^^^^^^
580
581This widget accepts the following specific options:
582
Georg Brandl44ea77b2013-03-28 13:28:44 +0100583 .. tabularcolumns:: |l|L|
584
Guilherme Polo5f238482009-01-28 14:41:10 +0000585 +----------+---------------------------------------------------------------+
Georg Brandl44ea77b2013-03-28 13:28:44 +0100586 | Option | Description |
Guilherme Polo5f238482009-01-28 14:41:10 +0000587 +==========+===============================================================+
588 | orient | One of "horizontal" or "vertical". Specifies the orientation |
589 | | of the progress bar. |
590 +----------+---------------------------------------------------------------+
591 | length | Specifies the length of the long axis of the progress bar |
592 | | (width if horizontal, height if vertical). |
593 +----------+---------------------------------------------------------------+
594 | mode | One of "determinate" or "indeterminate". |
595 +----------+---------------------------------------------------------------+
596 | maximum | A number specifying the maximum value. Defaults to 100. |
597 +----------+---------------------------------------------------------------+
598 | value | The current value of the progress bar. In "determinate" mode, |
599 | | this represents the amount of work completed. In |
Benjamin Petersond23f8222009-04-05 19:13:16 +0000600 | | "indeterminate" mode, it is interpreted as modulo *maximum*; |
Guilherme Polo5f238482009-01-28 14:41:10 +0000601 | | that is, the progress bar completes one "cycle" when its value|
Benjamin Petersond23f8222009-04-05 19:13:16 +0000602 | | increases by *maximum*. |
Guilherme Polo5f238482009-01-28 14:41:10 +0000603 +----------+---------------------------------------------------------------+
604 | variable | A name which is linked to the option value. If specified, the |
Benjamin Petersond23f8222009-04-05 19:13:16 +0000605 | | value of the progress bar is automatically set to the value of|
Guilherme Polo5f238482009-01-28 14:41:10 +0000606 | | this name whenever the latter is modified. |
607 +----------+---------------------------------------------------------------+
608 | phase | Read-only option. The widget periodically increments the value|
609 | | of this option whenever its value is greater than 0 and, in |
610 | | determinate mode, less than maximum. This option may be used |
611 | | by the current theme to provide additional animation effects. |
612 +----------+---------------------------------------------------------------+
613
614
615ttk.Progressbar
616^^^^^^^^^^^^^^^
617
618.. class:: Progressbar
619
Georg Brandl7f01a132009-09-16 15:58:14 +0000620 .. method:: start(interval=None)
Guilherme Polo5f238482009-01-28 14:41:10 +0000621
Benjamin Petersond23f8222009-04-05 19:13:16 +0000622 Begin autoincrement mode: schedules a recurring timer event that calls
Guilherme Polo5f238482009-01-28 14:41:10 +0000623 :meth:`Progressbar.step` every *interval* milliseconds. If omitted,
624 *interval* defaults to 50 milliseconds.
625
626
Georg Brandl7f01a132009-09-16 15:58:14 +0000627 .. method:: step(amount=None)
Guilherme Polo5f238482009-01-28 14:41:10 +0000628
Benjamin Petersond23f8222009-04-05 19:13:16 +0000629 Increments the progress bar's value by *amount*.
Guilherme Polo5f238482009-01-28 14:41:10 +0000630
631 *amount* defaults to 1.0 if omitted.
632
633
634 .. method:: stop()
635
636 Stop autoincrement mode: cancels any recurring timer event initiated by
Benjamin Petersond23f8222009-04-05 19:13:16 +0000637 :meth:`Progressbar.start` for this progress bar.
Guilherme Polo5f238482009-01-28 14:41:10 +0000638
639
640Separator
641---------
642
643The :class:`ttk.Separator` widget displays a horizontal or vertical separator
644bar.
645
Benjamin Petersond23f8222009-04-05 19:13:16 +0000646It has no other methods besides the ones inherited from :class:`ttk.Widget`.
Guilherme Polo5f238482009-01-28 14:41:10 +0000647
648
649Options
650^^^^^^^
651
652This widget accepts the following specific option:
653
Georg Brandl44ea77b2013-03-28 13:28:44 +0100654 .. tabularcolumns:: |l|L|
655
Guilherme Polo5f238482009-01-28 14:41:10 +0000656 +--------+----------------------------------------------------------------+
Georg Brandl44ea77b2013-03-28 13:28:44 +0100657 | Option | Description |
Guilherme Polo5f238482009-01-28 14:41:10 +0000658 +========+================================================================+
659 | orient | One of "horizontal" or "vertical". Specifies the orientation of|
660 | | the separator. |
661 +--------+----------------------------------------------------------------+
662
663
664Sizegrip
665--------
666
Benjamin Petersond23f8222009-04-05 19:13:16 +0000667The :class:`ttk.Sizegrip` widget (also known as a grow box) allows the user to
Guilherme Polo5f238482009-01-28 14:41:10 +0000668resize the containing toplevel window by pressing and dragging the grip.
669
Benjamin Petersond23f8222009-04-05 19:13:16 +0000670This widget has neither specific options nor specific methods, besides the
Guilherme Polo5f238482009-01-28 14:41:10 +0000671ones inherited from :class:`ttk.Widget`.
672
673
674Platform-specific notes
675^^^^^^^^^^^^^^^^^^^^^^^
676
Benjamin Petersond23f8222009-04-05 19:13:16 +0000677* On MacOS X, toplevel windows automatically include a built-in size grip
678 by default. Adding a :class:`Sizegrip` is harmless, since the built-in
Guilherme Polo5f238482009-01-28 14:41:10 +0000679 grip will just mask the widget.
680
681
682Bugs
683^^^^
684
685* If the containing toplevel's position was specified relative to the right
Benjamin Petersond23f8222009-04-05 19:13:16 +0000686 or bottom of the screen (e.g. ....), the :class:`Sizegrip` widget will
687 not resize the window.
Guilherme Polo5f238482009-01-28 14:41:10 +0000688* This widget supports only "southeast" resizing.
689
690
691Treeview
692--------
693
694The :class:`ttk.Treeview` widget displays a hierarchical collection of items.
695Each item has a textual label, an optional image, and an optional list of data
696values. The data values are displayed in successive columns after the tree
697label.
698
699The order in which data values are displayed may be controlled by setting
Benjamin Petersond23f8222009-04-05 19:13:16 +0000700the widget option ``displaycolumns``. The tree widget can also display column
Guilherme Polo5f238482009-01-28 14:41:10 +0000701headings. Columns may be accessed by number or symbolic names listed in the
702widget option columns. See `Column Identifiers`_.
703
704Each item is identified by an unique name. The widget will generate item IDs
705if they are not supplied by the caller. There is a distinguished root item,
Benjamin Petersond23f8222009-04-05 19:13:16 +0000706named ``{}``. The root item itself is not displayed; its children appear at the
Guilherme Polo5f238482009-01-28 14:41:10 +0000707top level of the hierarchy.
708
Benjamin Petersond23f8222009-04-05 19:13:16 +0000709Each item also has a list of tags, which can be used to associate event bindings
Guilherme Polo5f238482009-01-28 14:41:10 +0000710with individual items and control the appearance of the item.
711
712The Treeview widget supports horizontal and vertical scrolling, according to
713the options described in `Scrollable Widget Options`_ and the methods
714:meth:`Treeview.xview` and :meth:`Treeview.yview`.
715
716
717Options
718^^^^^^^
719
Benjamin Petersond23f8222009-04-05 19:13:16 +0000720This widget accepts the following specific options:
Guilherme Polo5f238482009-01-28 14:41:10 +0000721
Georg Brandl44ea77b2013-03-28 13:28:44 +0100722 .. tabularcolumns:: |l|p{0.7\linewidth}|
Georg Brandl2c860042009-06-16 19:24:38 +0000723
Guilherme Polo5f238482009-01-28 14:41:10 +0000724 +----------------+--------------------------------------------------------+
Georg Brandl44ea77b2013-03-28 13:28:44 +0100725 | Option | Description |
Guilherme Polo5f238482009-01-28 14:41:10 +0000726 +================+========================================================+
727 | columns | A list of column identifiers, specifying the number of |
728 | | columns and their names. |
729 +----------------+--------------------------------------------------------+
730 | displaycolumns | A list of column identifiers (either symbolic or |
731 | | integer indices) specifying which data columns are |
732 | | displayed and the order in which they appear, or the |
733 | | string "#all". |
734 +----------------+--------------------------------------------------------+
735 | height | Specifies the number of rows which should be visible. |
736 | | Note: the requested width is determined from the sum |
737 | | of the column widths. |
738 +----------------+--------------------------------------------------------+
739 | padding | Specifies the internal padding for the widget. The |
740 | | padding is a list of up to four length specifications. |
741 +----------------+--------------------------------------------------------+
742 | selectmode | Controls how the built-in class bindings manage the |
743 | | selection. One of "extended", "browse" or "none". |
744 | | If set to "extended" (the default), multiple items may |
745 | | be selected. If "browse", only a single item will be |
746 | | selected at a time. If "none", the selection will not |
747 | | be changed. |
748 | | |
749 | | Note that the application code and tag bindings can set|
Benjamin Petersond23f8222009-04-05 19:13:16 +0000750 | | the selection however they wish, regardless of the |
751 | | value of this option. |
Guilherme Polo5f238482009-01-28 14:41:10 +0000752 +----------------+--------------------------------------------------------+
753 | show | A list containing zero or more of the following values,|
754 | | specifying which elements of the tree to display. |
755 | | |
756 | | * tree: display tree labels in column #0. |
757 | | * headings: display the heading row. |
758 | | |
759 | | The default is "tree headings", i.e., show all |
760 | | elements. |
761 | | |
Benjamin Petersond23f8222009-04-05 19:13:16 +0000762 | | **Note**: Column #0 always refers to the tree column, |
Guilherme Polo5f238482009-01-28 14:41:10 +0000763 | | even if show="tree" is not specified. |
764 +----------------+--------------------------------------------------------+
765
766
767Item Options
768^^^^^^^^^^^^
769
770The following item options may be specified for items in the insert and item
771widget commands.
772
Georg Brandl44ea77b2013-03-28 13:28:44 +0100773 .. tabularcolumns:: |l|L|
774
Guilherme Polo5f238482009-01-28 14:41:10 +0000775 +--------+---------------------------------------------------------------+
Georg Brandl44ea77b2013-03-28 13:28:44 +0100776 | Option | Description |
Guilherme Polo5f238482009-01-28 14:41:10 +0000777 +========+===============================================================+
778 | text | The textual label to display for the item. |
779 +--------+---------------------------------------------------------------+
780 | image | A Tk Image, displayed to the left of the label. |
781 +--------+---------------------------------------------------------------+
782 | values | The list of values associated with the item. |
783 | | |
784 | | Each item should have the same number of values as the widget |
785 | | option columns. If there are fewer values than columns, the |
786 | | remaining values are assumed empty. If there are more values |
787 | | than columns, the extra values are ignored. |
788 +--------+---------------------------------------------------------------+
789 | open | True/False value indicating whether the item's children should|
790 | | be displayed or hidden. |
791 +--------+---------------------------------------------------------------+
792 | tags | A list of tags associated with this item. |
793 +--------+---------------------------------------------------------------+
794
795
796Tag Options
797^^^^^^^^^^^
798
799The following options may be specified on tags:
800
Georg Brandl44ea77b2013-03-28 13:28:44 +0100801 .. tabularcolumns:: |l|L|
802
Guilherme Polo5f238482009-01-28 14:41:10 +0000803 +------------+-----------------------------------------------------------+
Georg Brandl44ea77b2013-03-28 13:28:44 +0100804 | Option | Description |
Guilherme Polo5f238482009-01-28 14:41:10 +0000805 +============+===========================================================+
806 | foreground | Specifies the text foreground color. |
807 +------------+-----------------------------------------------------------+
808 | background | Specifies the cell or item background color. |
809 +------------+-----------------------------------------------------------+
810 | font | Specifies the font to use when drawing text. |
811 +------------+-----------------------------------------------------------+
812 | image | Specifies the item image, in case the item's image option |
813 | | is empty. |
814 +------------+-----------------------------------------------------------+
815
816
817Column Identifiers
818^^^^^^^^^^^^^^^^^^
819
820Column identifiers take any of the following forms:
821
822* A symbolic name from the list of columns option.
823* An integer n, specifying the nth data column.
824* A string of the form #n, where n is an integer, specifying the nth display
825 column.
826
827Notes:
828
829* Item's option values may be displayed in a different order than the order
830 in which they are stored.
831* Column #0 always refers to the tree column, even if show="tree" is not
832 specified.
833
834A data column number is an index into an item's option values list; a display
835column number is the column number in the tree where the values are displayed.
836Tree labels are displayed in column #0. If option displaycolumns is not set,
837then data column n is displayed in column #n+1. Again, **column #0 always
838refers to the tree column**.
839
840
841Virtual Events
842^^^^^^^^^^^^^^
843
844The Treeview widget generates the following virtual events.
845
Georg Brandl44ea77b2013-03-28 13:28:44 +0100846 .. tabularcolumns:: |l|L|
847
Guilherme Polo5f238482009-01-28 14:41:10 +0000848 +--------------------+--------------------------------------------------+
Georg Brandl44ea77b2013-03-28 13:28:44 +0100849 | Event | Description |
Guilherme Polo5f238482009-01-28 14:41:10 +0000850 +====================+==================================================+
851 | <<TreeviewSelect>> | Generated whenever the selection changes. |
852 +--------------------+--------------------------------------------------+
853 | <<TreeviewOpen>> | Generated just before settings the focus item to |
854 | | open=True. |
855 +--------------------+--------------------------------------------------+
856 | <<TreeviewClose>> | Generated just after setting the focus item to |
857 | | open=False. |
858 +--------------------+--------------------------------------------------+
859
860The :meth:`Treeview.focus` and :meth:`Treeview.selection` methods can be used
861to determine the affected item or items.
862
863
864ttk.Treeview
865^^^^^^^^^^^^
866
867.. class:: Treeview
868
Georg Brandl7f01a132009-09-16 15:58:14 +0000869 .. method:: bbox(item, column=None)
Guilherme Polo5f238482009-01-28 14:41:10 +0000870
871 Returns the bounding box (relative to the treeview widget's window) of
872 the specified *item* in the form (x, y, width, height).
873
874 If *column* is specified, returns the bounding box of that cell. If the
875 *item* is not visible (i.e., if it is a descendant of a closed item or is
876 scrolled offscreen), returns an empty string.
877
878
Georg Brandl7f01a132009-09-16 15:58:14 +0000879 .. method:: get_children(item=None)
Guilherme Polo5f238482009-01-28 14:41:10 +0000880
881 Returns the list of children belonging to *item*.
882
883 If *item* is not specified, returns root children.
884
885
886 .. method:: set_children(item, *newchildren)
887
Benjamin Petersond23f8222009-04-05 19:13:16 +0000888 Replaces *item*'s child with *newchildren*.
Guilherme Polo5f238482009-01-28 14:41:10 +0000889
Benjamin Petersond23f8222009-04-05 19:13:16 +0000890 Children present in *item* that are not present in *newchildren* are
891 detached from the tree. No items in *newchildren* may be an ancestor of
892 *item*. Note that not specifying *newchildren* results in detaching
Guilherme Polo5f238482009-01-28 14:41:10 +0000893 *item*'s children.
894
895
Georg Brandl7f01a132009-09-16 15:58:14 +0000896 .. method:: column(column, option=None, **kw)
Guilherme Polo5f238482009-01-28 14:41:10 +0000897
898 Query or modify the options for the specified *column*.
899
900 If *kw* is not given, returns a dict of the column option values. If
901 *option* is specified then the value for that *option* is returned.
902 Otherwise, sets the options to the corresponding values.
903
904 The valid options/values are:
905
906 * id
Benjamin Petersond23f8222009-04-05 19:13:16 +0000907 Returns the column name. This is a read-only option.
Guilherme Polo5f238482009-01-28 14:41:10 +0000908 * anchor: One of the standard Tk anchor values.
909 Specifies how the text in this column should be aligned with respect
910 to the cell.
911 * minwidth: width
912 The minimum width of the column in pixels. The treeview widget will
Benjamin Petersond23f8222009-04-05 19:13:16 +0000913 not make the column any smaller than specified by this option when
Guilherme Polo5f238482009-01-28 14:41:10 +0000914 the widget is resized or the user drags a column.
915 * stretch: True/False
Benjamin Petersond23f8222009-04-05 19:13:16 +0000916 Specifies whether the column's width should be adjusted when
Guilherme Polo5f238482009-01-28 14:41:10 +0000917 the widget is resized.
918 * width: width
919 The width of the column in pixels.
920
921 To configure the tree column, call this with column = "#0"
922
923 .. method:: delete(*items)
924
925 Delete all specified *items* and all their descendants.
926
927 The root item may not be deleted.
928
929
930 .. method:: detach(*items)
931
932 Unlinks all of the specified *items* from the tree.
933
934 The items and all of their descendants are still present, and may be
935 reinserted at another point in the tree, but will not be displayed.
936
937 The root item may not be detached.
938
939
940 .. method:: exists(item)
941
Serhiy Storchakafbc1c262013-11-29 12:17:13 +0200942 Returns ``True`` if the specified *item* is present in the tree.
Guilherme Polo5f238482009-01-28 14:41:10 +0000943
944
Georg Brandl7f01a132009-09-16 15:58:14 +0000945 .. method:: focus(item=None)
Guilherme Polo5f238482009-01-28 14:41:10 +0000946
947 If *item* is specified, sets the focus item to *item*. Otherwise, returns
948 the current focus item, or '' if there is none.
949
950
Georg Brandl7f01a132009-09-16 15:58:14 +0000951 .. method:: heading(column, option=None, **kw)
Guilherme Polo5f238482009-01-28 14:41:10 +0000952
953 Query or modify the heading options for the specified *column*.
954
955 If *kw* is not given, returns a dict of the heading option values. If
956 *option* is specified then the value for that *option* is returned.
957 Otherwise, sets the options to the corresponding values.
958
959 The valid options/values are:
960
961 * text: text
962 The text to display in the column heading.
963 * image: imageName
964 Specifies an image to display to the right of the column heading.
965 * anchor: anchor
966 Specifies how the heading text should be aligned. One of the standard
967 Tk anchor values.
968 * command: callback
969 A callback to be invoked when the heading label is pressed.
970
Benjamin Petersond23f8222009-04-05 19:13:16 +0000971 To configure the tree column heading, call this with column = "#0".
Guilherme Polo5f238482009-01-28 14:41:10 +0000972
973
974 .. method:: identify(component, x, y)
975
976 Returns a description of the specified *component* under the point given
977 by *x* and *y*, or the empty string if no such *component* is present at
978 that position.
979
980
981 .. method:: identify_row(y)
982
983 Returns the item ID of the item at position *y*.
984
985
986 .. method:: identify_column(x)
987
988 Returns the data column identifier of the cell at position *x*.
989
990 The tree column has ID #0.
991
992
993 .. method:: identify_region(x, y)
994
995 Returns one of:
996
997 +-----------+--------------------------------------+
998 | region | meaning |
999 +===========+======================================+
1000 | heading | Tree heading area. |
1001 +-----------+--------------------------------------+
1002 | separator | Space between two columns headings. |
1003 +-----------+--------------------------------------+
1004 | tree | The tree area. |
1005 +-----------+--------------------------------------+
1006 | cell | A data cell. |
1007 +-----------+--------------------------------------+
1008
1009 Availability: Tk 8.6.
1010
1011
1012 .. method:: identify_element(x, y)
1013
Benjamin Petersond23f8222009-04-05 19:13:16 +00001014 Returns the element at position *x*, *y*.
Guilherme Polo5f238482009-01-28 14:41:10 +00001015
1016 Availability: Tk 8.6.
1017
1018
1019 .. method:: index(item)
1020
1021 Returns the integer index of *item* within its parent's list of children.
1022
1023
Georg Brandl7f01a132009-09-16 15:58:14 +00001024 .. method:: insert(parent, index, iid=None, **kw)
Guilherme Polo5f238482009-01-28 14:41:10 +00001025
Benjamin Petersond23f8222009-04-05 19:13:16 +00001026 Creates a new item and returns the item identifier of the newly created
Guilherme Polo5f238482009-01-28 14:41:10 +00001027 item.
1028
1029 *parent* is the item ID of the parent item, or the empty string to create
1030 a new top-level item. *index* is an integer, or the value "end",
1031 specifying where in the list of parent's children to insert the new item.
1032 If *index* is less than or equal to zero, the new node is inserted at
Benjamin Petersond23f8222009-04-05 19:13:16 +00001033 the beginning; if *index* is greater than or equal to the current number
Guilherme Polo5f238482009-01-28 14:41:10 +00001034 of children, it is inserted at the end. If *iid* is specified, it is used
Benjamin Petersond23f8222009-04-05 19:13:16 +00001035 as the item identifier; *iid* must not already exist in the tree.
Guilherme Polo5f238482009-01-28 14:41:10 +00001036 Otherwise, a new unique identifier is generated.
1037
1038 See `Item Options`_ for the list of available points.
1039
1040
Georg Brandl7f01a132009-09-16 15:58:14 +00001041 .. method:: item(item, option=None, **kw)
Guilherme Polo5f238482009-01-28 14:41:10 +00001042
1043 Query or modify the options for the specified *item*.
1044
1045 If no options are given, a dict with options/values for the item is
1046 returned.
1047 If *option* is specified then the value for that option is returned.
1048 Otherwise, sets the options to the corresponding values as given by *kw*.
1049
1050
1051 .. method:: move(item, parent, index)
1052
1053 Moves *item* to position *index* in *parent*'s list of children.
1054
Benjamin Petersond23f8222009-04-05 19:13:16 +00001055 It is illegal to move an item under one of its descendants. If *index* is
1056 less than or equal to zero, *item* is moved to the beginning; if greater
1057 than or equal to the number of children, it is moved to the end. If *item*
Guilherme Polo5f238482009-01-28 14:41:10 +00001058 was detached it is reattached.
1059
1060
1061 .. method:: next(item)
1062
1063 Returns the identifier of *item*'s next sibling, or '' if *item* is the
1064 last child of its parent.
1065
1066
1067 .. method:: parent(item)
1068
1069 Returns the ID of the parent of *item*, or '' if *item* is at the top
1070 level of the hierarchy.
1071
1072
1073 .. method:: prev(item)
1074
1075 Returns the identifier of *item*'s previous sibling, or '' if *item* is
1076 the first child of its parent.
1077
1078
1079 .. method:: reattach(item, parent, index)
1080
1081 An alias for :meth:`Treeview.move`.
1082
1083
1084 .. method:: see(item)
1085
1086 Ensure that *item* is visible.
1087
Serhiy Storchakafbc1c262013-11-29 12:17:13 +02001088 Sets all of *item*'s ancestors open option to ``True``, and scrolls the
Guilherme Polo5f238482009-01-28 14:41:10 +00001089 widget if necessary so that *item* is within the visible portion of
1090 the tree.
1091
1092
Georg Brandl7f01a132009-09-16 15:58:14 +00001093 .. method:: selection(selop=None, items=None)
Guilherme Polo5f238482009-01-28 14:41:10 +00001094
1095 If *selop* is not specified, returns selected items. Otherwise, it will
1096 act according to the following selection methods.
1097
1098
1099 .. method:: selection_set(items)
1100
1101 *items* becomes the new selection.
1102
1103
1104 .. method:: selection_add(items)
1105
1106 Add *items* to the selection.
1107
1108
1109 .. method:: selection_remove(items)
1110
1111 Remove *items* from the selection.
1112
1113
1114 .. method:: selection_toggle(items)
1115
1116 Toggle the selection state of each item in *items*.
1117
1118
Georg Brandl7f01a132009-09-16 15:58:14 +00001119 .. method:: set(item, column=None, value=None)
Guilherme Polo5f238482009-01-28 14:41:10 +00001120
1121 With one argument, returns a dictionary of column/value pairs for the
1122 specified *item*. With two arguments, returns the current value of the
1123 specified *column*. With three arguments, sets the value of given
1124 *column* in given *item* to the specified *value*.
1125
1126
Georg Brandl7f01a132009-09-16 15:58:14 +00001127 .. method:: tag_bind(tagname, sequence=None, callback=None)
Guilherme Polo5f238482009-01-28 14:41:10 +00001128
1129 Bind a callback for the given event *sequence* to the tag *tagname*.
Benjamin Petersond23f8222009-04-05 19:13:16 +00001130 When an event is delivered to an item, the callbacks for each of the
Guilherme Polo5f238482009-01-28 14:41:10 +00001131 item's tags option are called.
1132
1133
Georg Brandl7f01a132009-09-16 15:58:14 +00001134 .. method:: tag_configure(tagname, option=None, **kw)
Guilherme Polo5f238482009-01-28 14:41:10 +00001135
1136 Query or modify the options for the specified *tagname*.
1137
1138 If *kw* is not given, returns a dict of the option settings for
1139 *tagname*. If *option* is specified, returns the value for that *option*
1140 for the specified *tagname*. Otherwise, sets the options to the
1141 corresponding values for the given *tagname*.
1142
1143
Georg Brandl7f01a132009-09-16 15:58:14 +00001144 .. method:: tag_has(tagname, item=None)
Guilherme Polo5f238482009-01-28 14:41:10 +00001145
1146 If *item* is specified, returns 1 or 0 depending on whether the specified
1147 *item* has the given *tagname*. Otherwise, returns a list of all items
Benjamin Petersond23f8222009-04-05 19:13:16 +00001148 that have the specified tag.
Guilherme Polo5f238482009-01-28 14:41:10 +00001149
1150 Availability: Tk 8.6
1151
1152
1153 .. method:: xview(*args)
1154
1155 Query or modify horizontal position of the treeview.
1156
1157
1158 .. method:: yview(*args)
1159
1160 Query or modify vertical position of the treeview.
1161
1162
1163.. _TtkStyling:
1164
1165Ttk Styling
1166-----------
1167
1168Each widget in :mod:`ttk` is assigned a style, which specifies the set of
1169elements making up the widget and how they are arranged, along with dynamic
1170and default settings for element options. By default the style name is the
Senthil Kumaranb4760ef2015-06-14 17:35:37 -07001171same as the widget's class name, but it may be overridden by the widget's style
Guilherme Polo5f238482009-01-28 14:41:10 +00001172option. If you don't know the class name of a widget, use the method
1173:meth:`Misc.winfo_class` (somewidget.winfo_class()).
1174
1175.. seealso::
1176
1177 `Tcl'2004 conference presentation <http://tktable.sourceforge.net/tile/tile-tcl2004.pdf>`_
1178 This document explains how the theme engine works
1179
1180
1181.. class:: Style
1182
1183 This class is used to manipulate the style database.
1184
1185
1186 .. method:: configure(style, query_opt=None, **kw)
1187
Benjamin Petersond23f8222009-04-05 19:13:16 +00001188 Query or set the default value of the specified option(s) in *style*.
Guilherme Polo5f238482009-01-28 14:41:10 +00001189
1190 Each key in *kw* is an option and each value is a string identifying
1191 the value for that option.
1192
1193 For example, to change every default button to be a flat button with
Raymond Hettinger238018c2009-04-08 08:23:44 +00001194 some padding and a different background color::
Guilherme Polo5f238482009-01-28 14:41:10 +00001195
1196 from tkinter import ttk
1197 import tkinter
1198
1199 root = tkinter.Tk()
1200
1201 ttk.Style().configure("TButton", padding=6, relief="flat",
1202 background="#ccc")
1203
1204 btn = ttk.Button(text="Sample")
1205 btn.pack()
1206
1207 root.mainloop()
1208
1209
1210 .. method:: map(style, query_opt=None, **kw)
1211
1212 Query or sets dynamic values of the specified option(s) in *style*.
1213
Benjamin Petersond23f8222009-04-05 19:13:16 +00001214 Each key in *kw* is an option and each value should be a list or a
1215 tuple (usually) containing statespecs grouped in tuples, lists, or
Raymond Hettinger238018c2009-04-08 08:23:44 +00001216 some other preference. A statespec is a compound of one
Benjamin Petersond23f8222009-04-05 19:13:16 +00001217 or more states and then a value.
Guilherme Polo5f238482009-01-28 14:41:10 +00001218
1219 An example may make it more understandable::
1220
1221 import tkinter
1222 from tkinter import ttk
1223
1224 root = tkinter.Tk()
1225
1226 style = ttk.Style()
1227 style.map("C.TButton",
1228 foreground=[('pressed', 'red'), ('active', 'blue')],
1229 background=[('pressed', '!disabled', 'black'), ('active', 'white')]
1230 )
1231
1232 colored_btn = ttk.Button(text="Test", style="C.TButton").pack()
1233
1234 root.mainloop()
1235
1236
Benjamin Petersond23f8222009-04-05 19:13:16 +00001237 Note that the order of the (states, value) sequences for an option does
Raymond Hettinger238018c2009-04-08 08:23:44 +00001238 matter, if the order is changed to ``[('active', 'blue'), ('pressed',
1239 'red')]`` in the foreground option, for example, the result would be a
1240 blue foreground when the widget were in active or pressed states.
Guilherme Polo5f238482009-01-28 14:41:10 +00001241
1242
Georg Brandl7f01a132009-09-16 15:58:14 +00001243 .. method:: lookup(style, option, state=None, default=None)
Guilherme Polo5f238482009-01-28 14:41:10 +00001244
1245 Returns the value specified for *option* in *style*.
1246
1247 If *state* is specified, it is expected to be a sequence of one or more
1248 states. If the *default* argument is set, it is used as a fallback value
1249 in case no specification for option is found.
1250
Raymond Hettinger238018c2009-04-08 08:23:44 +00001251 To check what font a Button uses by default::
Guilherme Polo5f238482009-01-28 14:41:10 +00001252
1253 from tkinter import ttk
1254
Ezio Melotti985e24d2009-09-13 07:54:02 +00001255 print(ttk.Style().lookup("TButton", "font"))
Guilherme Polo5f238482009-01-28 14:41:10 +00001256
1257
Georg Brandl7f01a132009-09-16 15:58:14 +00001258 .. method:: layout(style, layoutspec=None)
Guilherme Polo5f238482009-01-28 14:41:10 +00001259
1260 Define the widget layout for given *style*. If *layoutspec* is omitted,
1261 return the layout specification for given style.
1262
Benjamin Petersond23f8222009-04-05 19:13:16 +00001263 *layoutspec*, if specified, is expected to be a list or some other
1264 sequence type (excluding strings), where each item should be a tuple and
Guilherme Polo5f238482009-01-28 14:41:10 +00001265 the first item is the layout name and the second item should have the
Ezio Melottie130a522011-10-19 10:58:56 +03001266 format described in `Layouts`_.
Guilherme Polo5f238482009-01-28 14:41:10 +00001267
Benjamin Petersond23f8222009-04-05 19:13:16 +00001268 To understand the format, see the following example (it is not
1269 intended to do anything useful)::
Guilherme Polo5f238482009-01-28 14:41:10 +00001270
1271 from tkinter import ttk
1272 import tkinter
1273
1274 root = tkinter.Tk()
1275
1276 style = ttk.Style()
1277 style.layout("TMenubutton", [
1278 ("Menubutton.background", None),
1279 ("Menubutton.button", {"children":
1280 [("Menubutton.focus", {"children":
1281 [("Menubutton.padding", {"children":
1282 [("Menubutton.label", {"side": "left", "expand": 1})]
1283 })]
1284 })]
1285 }),
1286 ])
1287
1288 mbtn = ttk.Menubutton(text='Text')
1289 mbtn.pack()
1290 root.mainloop()
1291
1292
1293 .. method:: element_create(elementname, etype, *args, **kw)
1294
Benjamin Petersond23f8222009-04-05 19:13:16 +00001295 Create a new element in the current theme, of the given *etype* which is
Guilherme Polo5f238482009-01-28 14:41:10 +00001296 expected to be either "image", "from" or "vsapi". The latter is only
1297 available in Tk 8.6a for Windows XP and Vista and is not described here.
1298
1299 If "image" is used, *args* should contain the default image name followed
Benjamin Petersond23f8222009-04-05 19:13:16 +00001300 by statespec/value pairs (this is the imagespec), and *kw* may have the
Guilherme Polo5f238482009-01-28 14:41:10 +00001301 following options:
1302
1303 * border=padding
1304 padding is a list of up to four integers, specifying the left, top,
1305 right, and bottom borders, respectively.
1306
1307 * height=height
1308 Specifies a minimum height for the element. If less than zero, the
1309 base image's height is used as a default.
1310
1311 * padding=padding
1312 Specifies the element's interior padding. Defaults to border's value
1313 if not specified.
1314
1315 * sticky=spec
1316 Specifies how the image is placed within the final parcel. spec
Sandro Tosi2b373b02011-12-25 17:07:22 +01001317 contains zero or more characters "n", "s", "w", or "e".
Guilherme Polo5f238482009-01-28 14:41:10 +00001318
1319 * width=width
1320 Specifies a minimum width for the element. If less than zero, the
1321 base image's width is used as a default.
1322
Benjamin Petersond23f8222009-04-05 19:13:16 +00001323 If "from" is used as the value of *etype*,
1324 :meth:`element_create` will clone an existing
1325 element. *args* is expected to contain a themename, from which
Guilherme Polo5f238482009-01-28 14:41:10 +00001326 the element will be cloned, and optionally an element to clone from.
1327 If this element to clone from is not specified, an empty element will
Benjamin Petersond23f8222009-04-05 19:13:16 +00001328 be used. *kw* is discarded.
Guilherme Polo5f238482009-01-28 14:41:10 +00001329
1330
1331 .. method:: element_names()
1332
1333 Returns the list of elements defined in the current theme.
1334
1335
1336 .. method:: element_options(elementname)
1337
1338 Returns the list of *elementname*'s options.
1339
1340
Georg Brandl7f01a132009-09-16 15:58:14 +00001341 .. method:: theme_create(themename, parent=None, settings=None)
Guilherme Polo5f238482009-01-28 14:41:10 +00001342
1343 Create a new theme.
1344
1345 It is an error if *themename* already exists. If *parent* is specified,
1346 the new theme will inherit styles, elements and layouts from the parent
1347 theme. If *settings* are present they are expected to have the same
1348 syntax used for :meth:`theme_settings`.
1349
1350
1351 .. method:: theme_settings(themename, settings)
1352
1353 Temporarily sets the current theme to *themename*, apply specified
1354 *settings* and then restore the previous theme.
1355
1356 Each key in *settings* is a style and each value may contain the keys
1357 'configure', 'map', 'layout' and 'element create' and they are expected
1358 to have the same format as specified by the methods
1359 :meth:`Style.configure`, :meth:`Style.map`, :meth:`Style.layout` and
1360 :meth:`Style.element_create` respectively.
1361
Benjamin Petersond23f8222009-04-05 19:13:16 +00001362 As an example, let's change the Combobox for the default theme a bit::
Guilherme Polo5f238482009-01-28 14:41:10 +00001363
1364 from tkinter import ttk
1365 import tkinter
1366
1367 root = tkinter.Tk()
1368
1369 style = ttk.Style()
1370 style.theme_settings("default", {
1371 "TCombobox": {
1372 "configure": {"padding": 5},
1373 "map": {
1374 "background": [("active", "green2"),
1375 ("!disabled", "green4")],
1376 "fieldbackground": [("!disabled", "green3")],
1377 "foreground": [("focus", "OliveDrab1"),
1378 ("!disabled", "OliveDrab2")]
1379 }
1380 }
1381 })
1382
1383 combo = ttk.Combobox().pack()
1384
1385 root.mainloop()
1386
1387
1388 .. method:: theme_names()
1389
1390 Returns a list of all known themes.
1391
1392
Georg Brandl7f01a132009-09-16 15:58:14 +00001393 .. method:: theme_use(themename=None)
Guilherme Polo5f238482009-01-28 14:41:10 +00001394
Benjamin Petersond23f8222009-04-05 19:13:16 +00001395 If *themename* is not given, returns the theme in use. Otherwise, sets
Guilherme Polo5f238482009-01-28 14:41:10 +00001396 the current theme to *themename*, refreshes all widgets and emits a
1397 <<ThemeChanged>> event.
1398
1399
1400Layouts
1401^^^^^^^
1402
Benjamin Petersond23f8222009-04-05 19:13:16 +00001403A layout can be just None, if it takes no options, or a dict of
1404options specifying how to arrange the element. The layout mechanism
1405uses a simplified version of the pack geometry manager: given an
1406initial cavity, each element is allocated a parcel. Valid
1407options/values are:
Guilherme Polo5f238482009-01-28 14:41:10 +00001408
1409 * side: whichside
Benjamin Petersond23f8222009-04-05 19:13:16 +00001410 Specifies which side of the cavity to place the element; one of
Guilherme Polo5f238482009-01-28 14:41:10 +00001411 top, right, bottom or left. If omitted, the element occupies the
1412 entire cavity.
1413
1414 * sticky: nswe
1415 Specifies where the element is placed inside its allocated parcel.
1416
1417 * unit: 0 or 1
1418 If set to 1, causes the element and all of its descendants to be treated as
1419 a single element for the purposes of :meth:`Widget.identify` et al. It's
1420 used for things like scrollbar thumbs with grips.
1421
1422 * children: [sublayout... ]
1423 Specifies a list of elements to place inside the element. Each
1424 element is a tuple (or other sequence type) where the first item is
1425 the layout name, and the other is a `Layout`_.
1426
1427.. _Layout: `Layouts`_