Chapter 43. Basic Widget Methods

Table of Contents
Configuration
Event processing
Event callbacks
Alarm handlers and other non-event callbacks
Window management
Window Related Information
Miscellaneous
Tkinter Interface Methods
Option Database

The following methods are provided by all widgets (including the root window). In the method descriptions, self refer to the widget via which you reached the method.

The root window and other Toplevel windows provide additional methods. See the Window Methods section for more information.

Configuration

config

config(options...), configure(options...). Change one or more options for self.

config

config(), configure(). Return a dictionary containing the current settings for all widget options. For each option key in the dictionary, the value is either a five-tuple (option, option database key, option database class, default value, current value), or a two-tuple (option alias, option). The latter case is used for aliases like bg (background) and bd (borderwidth).

Note that the value fields aren't correctly formatted for some option types. See the description of the keys method for more information, and a workaround.

cget

cget(option). Return the current value for the given option.

Note that option values are always returned as strings (also if you gave a nonstring value when you configured the widget). Use int and float where appropriate.

keys

keys(). Return a tuple containing the options available for this widget. You can use cget to get the corresponding value for each option.

Note that the tuple currently include option aliases (like bd, bg, and fg). To avoid this, you can use config instead. On the other hand, config doesn't return valid option values for some option types (such as font names), so the best way is to use a combination of config and cget:

    for item in w.config():
        if len(item) == 5:
            option = item[0]
            value = w.cget(option)
            print option, value