Advertisement
182days

Radio Buttons

Dec 7th, 2023
837
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. import tkinter as tk
  2.  
  3. def on_radio_select():
  4.     selected_option = radio_var.get()
  5.    
  6.  
  7. # Create the main window
  8. root = tk.Tk()
  9. root.title("Radio Buttons Example")
  10.  
  11. # Create a StringVar to store the selected option
  12. radio_var = tk.StringVar()
  13.  
  14. # Create radio buttons
  15. radio_button1 = tk.Radiobutton(root, text="Fast", variable=radio_var, value="Fast", command=on_radio_select)
  16. radio_button2 = tk.Radiobutton(root, text="Medium", variable=radio_var, value="Medium", command=on_radio_select)
  17. radio_button3 = tk.Radiobutton(root, text="Slow", variable=radio_var, value="Slow", command=on_radio_select)
  18.  
  19. # Pack the radio buttons
  20. radio_button1.pack(anchor='w', padx=10)
  21. radio_button2.pack(anchor='w', padx=10)
  22. radio_button3.pack(anchor='w', padx=10)
  23.  
  24. # Set a default value
  25. radio_var.set("Medium")
  26.  
  27. # Start the GUI event loop
  28. root.mainloop()
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement