Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- def on_radio_select():
- selected_option = radio_var.get()
- # Create the main window
- root = tk.Tk()
- root.title("Radio Buttons Example")
- # Create a StringVar to store the selected option
- radio_var = tk.StringVar()
- # Create radio buttons
- radio_button1 = tk.Radiobutton(root, text="Fast", variable=radio_var, value="Fast", command=on_radio_select)
- radio_button2 = tk.Radiobutton(root, text="Medium", variable=radio_var, value="Medium", command=on_radio_select)
- radio_button3 = tk.Radiobutton(root, text="Slow", variable=radio_var, value="Slow", command=on_radio_select)
- # Pack the radio buttons
- radio_button1.pack(anchor='w', padx=10)
- radio_button2.pack(anchor='w', padx=10)
- radio_button3.pack(anchor='w', padx=10)
- # Set a default value
- radio_var.set("Medium")
- # Start the GUI event loop
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement