Radio button bar : Radiobutton « Tkinker « Python Tutorial






Radio button bar
from Tkinter import *
     
class Radiobar(Frame):
    def __init__(self, parent=None, picks=[], side=LEFT, anchor=W):
        Frame.__init__(self, parent)
        self.var = StringVar()
        for pick in picks:
            rad = Radiobutton(self, text=pick, value=pick, variable=self.var)
            rad.pack(side=side, anchor=anchor, expand=YES)
    def state(self):
        return self.var.get()
     
root = Tk()
radioButtonBar = Radiobar(root, ['a', 'b', 'c'], side=TOP, anchor=NW)

radioButtonBar.pack(side=LEFT, fill=Y)

radioButtonBar.config(relief=RIDGE,  bd=2)

def allstates(): 
   print radioButtonBar.state()

Button(root, text='Peek', command=allstates).pack(side=RIGHT)
root.mainloop()








18.26.Radiobutton
18.26.1.Radio buttons, the easy wayRadio buttons, the easy way
18.26.2.Hold on to your radio variables (an obscure thing, indeed)Hold on to your radio variables (an obscure thing, indeed)
18.26.3.Deselect for radio buttons simply sets the button's associated value to a null stringDeselect for radio buttons simply sets the button's associated value to a null string
18.26.4.See what happens when some buttons have same valueSee what happens when some buttons have same value
18.26.5.Add RadioButton to a groupAdd RadioButton to a group
18.26.6.Bind variable to RadioButtonBind variable to RadioButton
18.26.7.Radio button barRadio button bar
18.26.8.Use Radio buttons to change the fontUse Radio buttons to change the font