Create Font Chooser App – Python Tkinter GUI Tutorial 192

In this video I’ll show you how to create a cool little font family picker with Tkinter and Python.

We’ll use tkinter Font() to access all the available font’s on your computer and add them to a listbox that you can scroll thru and click on.

When you click on a font, we’ll update the font in a textbox with that font family using a binding.

Python Code: font_dialog.py
(Github Code)

from tkinter import *
from tkinter import font

root = Tk()
root.title('Codemy.com - Font Dialog Box')
root.iconbitmap('c:/gui/codemy.ico')
root.geometry("500x500")

# Create font chooser function
def font_chooser(e):
	our_font.config(
		family=my_listbox.get(my_listbox.curselection()))

# Designate Our Font
our_font = font.Font(family="Helvetica", size="32")

# Add Frame
my_frame = Frame(root, width=480, height=275)
my_frame.pack(pady=10)
# Freeze Frame in place
my_frame.grid_propagate(False)
my_frame.columnconfigure(0, weight=10)

# Add Text Box
my_text = Text(my_frame, font=our_font)
my_text.grid(row=0, column=0)
my_text.grid_rowconfigure(0, weight=1)
my_text.grid_columnconfigure(0, weight=1)

# Add Listbox
my_listbox = Listbox(root, selectmode=SINGLE, width=80)
my_listbox.pack()

# Add Font Families To Listbox
for f in font.families():
	my_listbox.insert('end', f)

# Bind The Listbox
my_listbox.bind('', font_chooser)

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

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...