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