Next / Previous / Contents / TCC Help System / NM Tech homepage

46. Methods common to all ttk widgets

The methods shown here are available on all the ttk widgets.

.cget(option)

This method returns the value for the specified option.

.configure(option=value, ...)

To set one or more widget options, use keyword arguments of the form option=value. For example, to set a widget's font, you might use an argument such as “font=('serif', 12)”.

If you provide no arguments, the method will return a dictionary of all the widget's current option values. In this dictionary, the keys will be the option names, and each related value will be a tuple (name, dbName, dbClass, default, current):

name The option name.
dbName The database name of the option.
dbClass The database class of the option.
default The default value of the option.
current The current value of the option.
.identify(x, y)

Use this to determine what element is at a given location within the widget. If the point (x, y) relative to the widget is somewhere within the widget, this method returns the name of the element at that position; otherwise it returns an empty string.

.instate(stateSpec, callback=None, *args, **kw)

The purpose of this to determine whether the widget is in a specified state or combination of states.

If you provide a callable value as the callback argument, and the widget matches the state or combination of states specified by the stateSpec argument, that callable will be called with positional arguments *args and keyword arguments **kw. If the widget's state does not match stateSpec, the callback will not be called.

If you don't provide a callback argument, the method will return True if the widget's state matches stateSpec, False otherwise.

For the structure of the stateSpec argument, see Section 46.1, “Specifying widget states in ttk.

.state(stateSpec=None)

Use this item either to query a widget to determine its current states, or to set or clear one state.

If you provide a stateSpec argument of the form described in Section 46.1, “Specifying widget states in ttk, the method will set or clear states in the widget according to that argument.

For example, for a widget w, the method w.state(['!disabled', 'selected']) would clear the widget's 'disabled' set and set its 'selected' state.