Tkinter Combobox

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()

Mini Quiz

0%

Tkinter - Quiz 7

1 / 5

Q1. Which Tkinter module contains the Combobox widget?

2 / 5

Q2. What is the main advantage of using a Combobox?

3 / 5

Q3. Which method is used to set the default selected item in a Combobox?

4 / 5

Q4. Which method is used to retrieve the currently selected value from a Combobox?

5 / 5

Q5. Why is a Combobox preferred over multiple Radiobutton widgets in some applications?

Your score is

The average score is 0%

0%

Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.

Scroll to Top