pythonware.com | products ::: library ::: search ::: daily Python-URL! |
Widget ConfigurationChapter 5. Widget Configuration
To control the appearance of a widget, you usually use options rather than method calls. Typical options include text and color, size, command callbacks, etc. To deal with options, all core widgets implement the same configuration interface: Configuration Interface
Note that some options have names that are reserved words in Python (class, from, ...). To use these as keyword arguments, simply append an underscore to the option name (class_, from_, ...). Note that you cannot set the name option using this method; it can only be set when the widget is created. For convenience, the widgets also implement a partial dictionary interface. The __setitem__ method maps to configure, while __getitem__ maps to cget. As a result, you can use the following syntax to set and query options: value = widget[option] widget[option] = value Note that each assignment results in one call to Tk. If you wish to change multiple options, it is usually a better idea to change them with a single call to config or configure (personally, I prefer to always change options in that fashion). The following dictionary method also works for widgets:
|