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

31. ttk.Combobox

This widget is a combination of an Entry and a drop-down menu. In your application, you will see the usual text entry area, with a downward-pointing arrow. When the user clicks on the arrow, a drop-down menu appears. If the user clicks on one, that choice replaces the current contents of the entry. However, the user may still type text directly into the entry (when it has focus), or edit the current text.

To create a ttk.Combobox widget as the child of a given parent widget:

    w = ttk.Combobox(parent, option=value, ...)


Table 39. ttk.Combobox options

class_ The widget class name. This may be specified when the widget is created, but cannot be changed later. For an explanation of widget classes, see Section 27, “Standardizing appearance”.
cursor The cursor that will appear when the mouse is over the checkbutton; see Section 5.8, “Cursors”.
exportselection By default, if you select text within an Entry widget, it is automatically exported to the clipboard. To avoid this exportation, use exportselection=0.
height Use this option to specify a maximum number of rows that will appear in the drop-down menu; the default is 20. If there are more values than this number, the drop-down menu will automatically include a vertical scrollbar.
justify This option specifies how the text will be positioned within the entry area when it does not completely fill the area. Values may be tk.LEFT to left-justify; tk.CENTER to center; or tk.RIGHT to right-justify.
postcommand You may use this option to supply a callback function that will be invoked when the user clicks on the down-arrow. This callback may change the values option; if so, the changes will appear in the drop-down menu.
style The style to be used in rendering this checkbutton; see Section 49, “Using and customizing ttk styles”.
takefocus By default, a ttk.Checkbutton will be included in focus traversal; see Section 53, “Focus: routing keyboard input”. To remove the widget from focus traversal, use takefocus=False.
textvariable A variable that controls the text that appears in the entry area; see Section 52, “Control variables: the values behind the widgets”.
validate You may use this option to request dynamic validation of the widget's text content. See Section 10.2, “Adding validation to an Entry widget”.
validatecommand You may use this option to specify a callback function that dynamically validates the widget's text content. See Section 10.2, “Adding validation to an Entry widget”.
values The choices that will appear in the drop-down menu, as a sequence of strings.
width This option specifies the width of the entry area as a number of characters. The actual width will be this number times the average width of a character in the effective font. The default value is 20.
xscrollcommand If the widget has an associated horizontal scrollbar, set this option to the .set method of that scrollbar.

Methods on a ttk.Combobox include all those described in Section 46, “Methods common to all ttk widgets”, plus all the methods on the Tkinter widget described in Section 10, “The Entry widget”, plus:


To select one of the elements of the values option, pass the index of that element as the argument to this method. If you do not supply an argument, the returned value is the index of the current entry text in the values list, or -1 if the current entry text is not in the values list.


Set the current text in the widget to value.

The states of a ttk.Combobox widget affect its operation. To interrogate or change states, see the .instate() and .state() methods in Section 46, “Methods common to all ttk widgets”.