Checkbox button bar : Checkbutton « Tkinker « Python Tutorial






Checkbox button bar
from Tkinter import *
     
class Checkbar(Frame):
    def __init__(self, parent=None, picks=[], side=LEFT, anchor=W):
        Frame.__init__(self, parent)
        self.vars = []
        for pick in picks:
            var = IntVar()
            chk = Checkbutton(self, text=pick, variable=var)
            chk.pack(side=side, anchor=anchor, expand=YES)
            self.vars.append(var)
    def state(self):
        return [var.get() for var in self.vars]  

root = Tk()
checkBoxBar = Checkbar(root, ['A', 'B', 'C', 'D'])

checkBoxBar.pack(side=TOP,  fill=X)

checkBoxBar.config(relief=GROOVE, bd=2)

def allstates(): 
   print checkBoxBar.state()

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








18.6.Checkbutton
18.6.1.Check buttons, the easy wayCheck buttons, the easy way
18.6.2.Check buttons, the hard way (without variables)Check buttons, the hard way (without variables)
18.6.3.Checkbox button barCheckbox button bar
18.6.4.Use Check buttons to change the fontUse Check buttons to change the font
18.6.5.React to the check state of a check boxReact to the check state of a check box
18.6.6.RadioButtons and CheckButtonRadioButtons and CheckButton