a list of Checkbuttons

William Gill noreply at gcgroup.net
Mon Aug 29 19:20:09 EDT 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]) )
    Checkbutton(master,
                text=str(classification[0])+': '+classification[1] ,
                variable=classifications[-1]).grid(row=count)



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?

Thanks,

Bill



More information about the Python-list mailing list