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