In this video we’ll learn about ComboBoxes in Tkinter and Python.

A Combo Box is a drop down menu for TKinter.

It’s actually a TTK Widget, and I’ll show you how to create them and manipulate them programatically in this video.

Python Code: combo_box.py
(Github Code)

from tkinter import *
from tkinter import ttk

root = Tk()
root.title("ComboBoxes - Intro To Tkinter")
root.iconbitmap('images/tkinter.ico')
root.geometry('600x400')

def submit():
	my_label.config(text=my_combo.get())
	#my_combo.set("Cheese")

	# Output the whole list
	#items=""
	#for thing in my_combo['values']:
	#	items = items + thing + "\n"
	#my_label.config(text=items)

# Create a ComboBox
my_list = ["Peperroni", "Cheese", "Mushroom"]
my_combo = ttk.Combobox(root, values=my_list, state="readonly", width=20, font=("Helvetica", 18))
my_combo.pack(pady=20)

# set default item
my_combo.set("Peperroni")


my_label = Label(root, text="", font=("Helvetica", 18))
my_label.pack(pady=20)

my_button = Button(root, text="Submit", command=submit)
my_button.pack(pady=20)


root.mainloop()



John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of the first dot com boom. After that he developed the award-winning Submission-Spider search engine submission software that's been used by over 3 million individuals, businesses, and governments in over 42 countries. He's written several Amazon #1 best selling books on coding, and runs a popular Youtube coding channel.

View all posts

Add comment

Your email address will not be published. Required fields are marked *

John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of...