In this video I’ll show you how to use Radio Buttons with TTKBootstrap, Tkinter, and Python.

There are a couple of ways to make RadioButtons with Tkinter; actual toggle boxes and square buttons. We’ll look at both.

I’ll also show you how to create radio buttons from a Python list.

Python Code: rad.py
(Github Code)

from tkinter import *
import ttkbootstrap as tb

root = tb.Window(themename="superhero")

#root = Tk()
root.title("TTK Bootstrap! Radio Buttons")
root.iconbitmap('images/codemy.ico')
root.geometry('500x550')

# Clicker Function
def clicker():
	my_label.config(text=f'You Selected: {my_topping.get()}')


# Create Radio Button List
toppings = ["Pepperoni", "Cheese", "Veggie"]

# Create A Tkinter Variable To Keep Track of everything
my_topping = StringVar()

# Loop thru the list and create radio buttons
for topping in toppings:
	tb.Radiobutton(root, bootstyle="danger", variable=my_topping, text=topping, value=topping, command=clicker).pack(pady=20)

# Create button
my_button = tb.Button(root, text="Click Me!", command=clicker)
my_button.pack(pady=20)

# Create a Label 
my_label = tb.Label(root, text="You Selected: ")
my_label.pack(pady=20)

# Create actual Radio Button Buttons
rb1 = tb.Radiobutton(root, bootstyle="info toolbutton", variable=my_topping, text="Radio Button 1", value="Radio Button 1", command=clicker)
rb1.pack(pady=20)

rb2 = tb.Radiobutton(root, bootstyle="info toolbutton outline", variable=my_topping, text="Radio Button 2", value="Radio Button 2", command=clicker)
rb2.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...