The Radiobuton is one-of-many type button. There are more than one options in the selection, but the user could only select one of them. The same as introduced widgets before, Radibutton could contain text or image and could bind callback function or method to it. This callback function is trigger automatically when that button is pressed.
Tkinter Radiobutton Basic Example
The result of above Radiobutton basic demo is below
radioValue = tk.IntVar()
Just as check button, radio buttons need to associate values of particular data type with them.
rdioOne = tk.Radiobutton(app, text='January', variable=radioValue, value=1) rdioTwo = tk.Radiobutton(app, text='Febuary', variable=radioValue, value=2) rdioThree = tk.Radiobutton(app, text='March', variable=radioValue, value=3)
Here, there buttons with the text of “January”, “February” and “March” are created here. Radio buttons in the same group shall and must have unique values.
Change Tkinter Radiobutton Indicator Type
The default radio button indicator is a circular hole with white space inside, but it could also be replaced with a box containing text or image. The text box is raised when the radio button is not selected, and is sunken when it is pressed.
rdioOne = tk.Radiobutton(app, text='I am raised', variable=radioValue, value=1, indicatoron = 0)
indicatoron is the option to enable raido button circular hole indictor on or off.
Bind Tkinter Radiobutton Callback Function
It is the exactly the same with Tkinter Checkbutton in the option how to set the button callback function. Use option