pythonware.com products ::: library ::: search ::: daily Python-URL!

Library

An Introduction to Tkinter

Basic Widget Methods :::

   

Basic Widget Methods

Back    Next   

 Chapter 44. Basic Widget Methods

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, 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.

 cget

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

Note that option values are always returned as strings. Use int and float where appropriate.

 keys

keys(). Return a tuple containing the options available for this widget.

Note that the tuple currently includes option aliases (like bd, bg, and fg).

Recommended approach:

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

Back    Next