Thomas Kilian Thomas Kilian - 2 months ago 14
Python Question

ComboBox not present in TK

According to the docs there should be a

ComboBox
operation in TK, but I can't find it.
dir(tk)
shows


['ACTIVE', 'ALL', 'ANCHOR', 'ARC', 'At', 'AtEnd', 'AtInsert', 'AtSelFirst', 'AtSelLast', 'BASELINE', 'BEVEL', 'BOTH', 'BOTTOM', 'BROWSE', 'BUTT', 'BaseWidget', 'BitmapImage', 'BooleanType', 'BooleanVar', 'BufferType', 'BuiltinFunctionType', 'BuiltinMethodType', 'Button', 'CASCADE', 'CENTER', 'CHAR', 'CHECKBUTTON', 'CHORD', 'COMMAND', 'CURRENT', 'CallWrapper', 'Canvas', 'Checkbutton', 'ClassType', 'CodeType', 'ComplexType', 'DISABLED', ...


The version is

import Tkinter as tk
tk.__version__



'$Revision: 81008 $'


on my Mac (latest OS X 10.11.6). No brewery for python whatsoever.

Answer

There is no ComboBox widget in tkinter, what you are looking for is tkinter.ttk (in Python 3, in Python 2 it's just called ttk), which provides themed tk widgets. Docs for tkinter.ttk, and subsection for ComboBox.

You can use this code to import ttk and use its widgets rather than standard tkinter ones:

Python 2

from Tkinter import *
from ttk import *

Python 3:

from tkinter import *
from tkinter.ttk import *
Comments