Radiobutton
Radiobutton is a widget that lets us choose an option from multiple options. Tkinter provides Radiobutton using which we can display multiple options in our GUI application.
Syntax:
tk.Radiobutton(text=some_name,value=give_name_that_of_text,variable=Tkinter_Variable)
for option in [“Brown”,”Black”,”Orange”,”Green”,”Red”]:
rd = tk.Radiobutton(root,text=”%s” %option,value=option,variable=choice)
rd.pack()
In order to display a Variable for each Radiobutton, we shall initialize Tkinter String Variable. Using String Variable we can perform the set and get method. Initially using String Variable we shall initialize Purple as the default color.
Syntax:
var = tk.StringVar()
choice = tk.StringVar(root,"purple") # initialize # after button click: color = choice.get()
How To Change Multiple Background Colours In Tkinter?
In this article, we shall see how to change or switch between Multiple Background colors in Tkinter.