Check box bar: get selected check box : CheckBox « GUI Tk « Python

Home
Python
1.2D
2.Application
3.Buildin Function
4.Class
5.Data Structure
6.Data Type
7.Database
8.Development
9.Dictionary
10.Event
11.Exception
12.File
13.Function
14.GUI Pmw
15.GUI Tk
16.Language Basics
17.List
18.Math
19.Network
20.String
21.System
22.Thread
23.Tuple
24.Utility
25.XML
Python » GUI Tk » CheckBoxScreenshots 
Check box bar: get selected check box
Check box bar: get selected check box



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.Border for a group of check boxesBorder for a group of check boxes
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.