Next / Previous / Contents / Shipman's homepage

46. Methods common to all ttk widgets

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


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.


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.

46.1. Specifying widget states in ttk

Several methods within ttk require a stateSpec argument that specifies a particular widget state or combination of states. This argument may be any of the following:

  • A single state name such as 'pressed'. A ttk.Button widget is in this state, for example, when the mouse cursor is over the button and mouse button 1 is down.

  • A single state name preceded with an exclamation point (!); this matches the widget state only when that state is off.

    For example, a stateSpec argument '!pressed' specifies a widget that is not currently being pressed.

  • A sequence of state names, or state names preceded by an '!'. Such a stateSpec matches only when all of its components match. For example, a stateSpec value of ('!disabled', 'focus') matches a widget only when that widget is not disabled and it has focus.