Tkinter Combobox

python tkinter python tutorial

Combobox in tkinter is a drop down list, which can hold multiple values and show one item at a time. Combobox is useful for select one option in many choice. Combobox widget is a class of ttk module of tkinter library, so you need to import this module. Below combobox tkinter tutorial will show you example, how to add and show drop-down Tk() window.

Python Tkinter Combobox Example

from tkinter import *
from tkinter import ttk
win =Tk()
win.geometry('200x100')
course=["Java","Python","C & C++"]
l1=Label(win,text="Choose Your Favourite Language")
l1.grid(column=0, row=0)
cb=ttk.Combobox(win,values=course,width=10)
cb.grid(column=0, row=1)
cb.current(0)
win.mainloop()

Combobox Tkinter Event Example

from tkinter import *
from tkinter import ttk
def func():
    l2.configure(text=cb.get())
win =Tk()
win.geometry('200x100')
course=["Java","Python","C & C++"]
l1=Label(win,text="Choose Your Favourite Language")
l1.grid(column=0, row=0)
cb=ttk.Combobox(win,values=course,width=10)
cb.grid(column=0, row=1)
cb.current(0)
b=Button(win,text="Click Here",command=func)
b.grid(column=0, row=2)
l2=Label(win,text="")
l2.grid(column=0, row=3)
win.mainloop()