Skip to content

Instantly share code, notes, and snippets.

@elowy01
Last active June 14, 2022 16:24
Show Gist options
  • Save elowy01/b34b28b06033fe80442da7c1b1e60cfb to your computer and use it in GitHub Desktop.
Save elowy01/b34b28b06033fe80442da7c1b1e60cfb to your computer and use it in GitHub Desktop.
import tkinter as tk
from tkinter import ttk
from tkinter.messagebox import showinfo
# root window
root = tk.Tk()
root.geometry('300x220')
root.resizable(False, False)
root.title('Radio Button Demo')
def show_selected_size():
showinfo(
title='Result',
message=selected_size.get()
)
selected_size = tk.StringVar()
sizes = (('Small', 'S'),
('Medium', 'M'),
('Large', 'L'),
('Extra Large', 'XL'),
('Extra Extra Large', 'XXL'))
# label
label = ttk.Label(text="What's your t-shirt size?")
label.pack(fill='x', padx=5, pady=5)
# radio buttons
for size in sizes:
r = ttk.Radiobutton(
root,
text=size[0],
value=size[1],
variable=selected_size
)
r.pack(fill='x', padx=5, pady=5)
# button
button = ttk.Button(
root,
text="Get Selected Size",
command=show_selected_size)
button.pack(fill='x', padx=5, pady=5)
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment