a list of Checkbuttons

W

William Gill

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top