Tkinter Combobox is the drop-down list for the user to choose from. It is a combination of
drop-down menu as you can see. When you click the arrow on the left side, you will see a drop-down menu showing all the choices, and if you click on one, it will replace the current
Python Tkinter Combobox Example
from tkinter import ttk
Tkinter combobox widget is in the
ttk module of Tkinter, therefore, you need to import this module to use this widget.
comboExample = ttk.Combobox(app, values=[ "January", "February", "March", "April"])
It creates the Tkinter combobox widget instance and also assigns the values that will appear in the drop-down list.
Normally, the default item showing in the combobox is the first element in the values list. You could also change it to any element by using
You could also use
current() to get the index of the current selected element, and use
get() method to get the element itself.
Tkinter Combobox Event Binding
The combobox callback function binding is different from the widgets introduced in last chapters.
bind() method is the way to bind the callback function with the combobox virtual event when the user selects an element in the drop-down list.
def callbackFunc(event): print("New Element Selected")
This is the defined callback function whenever you select an element from the list.
eventshall not be skipped as the passing argument, it is passed form the combobox virtual event
It binds the virtual event
<<ComboboxSelected>> with the callback function.
Every time you select a new element from the list, it prints
New Element Selected