Tkinter Widget-Radiobutton

This widget is used to create multiple choice options in GUI Application.
Syntax-

w = Radiobutton ( main, option)

Parameter-

Main- parent Window.
Option- attribute of button widget.

Example-
  1. from tkinter import *  
  2. def sel():  
  3. selection = "selected" + str(var.get())  
  4. label.config(text = selection)  
  5. main = Tk()  
  6. var = IntVar()  
  7. R1 = Radiobutton(main, text="C# corner", variable=var, value=1,  
  8. command=sel)  
  9. R1.pack( anchor = W )  
  10. R2 = Radiobutton(main, text="Python", variable=var, value=2,  
  11. command=sel)  
  12. R2.pack( anchor = W )  
  13. R3 = Radiobutton(main, text=".Net", variable=var, value=3,  
  14. command=sel)  
  15. R3.pack( anchor = W)  
  16. label = Label(main)  
  17. label.pack()  
  18. main.mainloop()  
Output-

 Option Description
 activebackgroundIt sets background color of widgets when widget is under the cursor.
activeforeground
It sets foreground color of widget when widget is under the cursor.
anchor
It is used to set the position of the text.
bg
The normal background color behind the indicator and label.
bitmap
It is used to display a monochrome image on a radiobutton.
borderwidth
It sets the border width in pixels. Default is 2.
command
It is used to call a method.
cursor
Cursor is used to create a cursor in widgets like arrow, circle, dot etc.
font
It is used to change the font of the text.
fg
The color is used to render the text.
height
It is used to set the height of radiobutton.
highlightbackground
It is used to change the highlightbackground color.
highlightcolor
It changes the color of widgets on focus.
image
It is used to set the image
justify
It is used to justify the text of widgets.
padx
It is used to add additional padding on left and right of the text of widgets and default is 1.
pady
It is used to add additional padding above and below the text of widgets. Default is 1.
relief
Relief is special type of border. The values are SUNKEN, RAISED, GROOVE and RIDGE.
selectcolor
It is used to change the color of radiobutton, when radiobutton is selected.
selectimage
It is used to set the image on option to select.
state
It is used to change the state of radiobutton
text
It is used to add the text after the radiobutton.
textvariable
It is used to store the value of widgets.
underline
It is used to underline and default is -1, which means no underline text.
value
It is used to define the value of radiobutton.
variable
It is used to share the values of radiobutton.
width
It is used to define the width of widgets.
wraplength
v
Summary

In this chapter, you learnt what Radiobutton widget is and how to use the property of the widget.
Next » Tkinter Widget-Scale