Border for a group of check boxes : CheckBox « GUI Tk « Python






Border for a group of check boxes

Border for a group of check boxes


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 map((lambda var: var.get()), self.vars)


class Quitter(Frame):                      
    def __init__(self, parent=None):      
        Frame.__init__(self, parent)
        self.pack()
        widget = Button(self, text='Quit', command=self.quit)
        widget.pack(expand=YES, fill=BOTH, side=LEFT)
    def quit(self):
        ans = askokcancel('Verify exit', "Really quit?")
        if ans: Frame.quit(self)


if __name__ == '__main__':
    root = Tk()
    lng = Checkbar(root, ['Python', 'C#', 'Java', 'C++'])
    tgl = Checkbar(root, ['All'])
    lng.pack(side=TOP,  fill=X)
    tgl.pack(side=LEFT)
    lng.config(relief=GROOVE, bd=2)

    def allstates(): print lng.state(), tgl.state()
    Quitter(root).pack(side=RIGHT)
    Button(root, text='Peek', command=allstates).pack(side=RIGHT)
    root.mainloop()

           
       








Related examples in the same category

1.Check Button Demo: disabledCheck Button Demo: disabled
2.Get check box statesGet check box states
3.Save check box statesSave check box states
4.A check box buttonA check box button
5.Add a check box to a DialogAdd a check box to a Dialog
6.Check box bar: get selected check boxCheck box bar: get selected check box