a list of Checkbuttons

William Gill noreply at gcgroup.net
Tue Aug 30 01:20:09 CEST 2005

OK I'm tired, I've got a cold, and my brain isn't working very well.  I 
have a result set ( a tuple of tuples) from a db.  Each element has two 
elements; classification number, and classification heading.  i.e. 
result=((001,'heading one'),(002,'heading two'),...)

classification numbers may not be in numerical order, and may skip 
numbers, so they are not good as an index.

I want to create tkinter Checkbuttons that allow me to select which 
apply to the record I'm editing.  What comes to my sub-par mind is to 
create a list and assign Checkbuttons to each element.  something like:

classifications = []
for count, classification in enumerate(result):
    classifications.append( (IntVar(),classification[0]) )
                text=str(classification[0])+': '+classification[1] ,

then to collect which boxes are checked:

for check in classifications:
     if check[0].get() == 1:
        print 'classification number %s selected"  % check[1][0]

Is this the smartest way to do this?  It should work, but will I be able 
to understand this 6 months from now?



More information about the Python-list mailing list