Python Devlopment






Radiobutton



It is used to offer multi-choice option to the user. It offers several options to the user and the user has to choose one option.
The general syntax is:

rb = Radiobutton(win, option=value)

There are number of options which are used to change the format of this widget. Number of options can be passed as parameters separated by commas. Some of them are listed below.

  • activebackground: to set the background color when widget is under the cursor.
  • activeforeground: to set the foreground color when widget is under the cursor.
  • bg: to set he normal background color.
  • command: to call a function.
  • font: to set the font on the button label.
  • image: to set the image on the widget.
  • width: to set the width of the label in characters.
  • height: to set the height of the label in characters.
Example:
from Tkinter import *
win=Tk()
win.title('My Radio Button')
win.geometry('350x250')
var=IntVar()
rb1=Radiobutton(win,text="Python",variable=var,value=1)
rb1.pack()
rb2=Radiobutton(win,text="Ruby",variable=var,value=2)
rb2.pack()
rb3=Radiobutton(win,text="Java",variable=var,value=3)
rb3.pack()
win.mainloop()