multiple checkboxes highlighted when one clicked = not good

M

MooMaster

I've been reading Deitel's Introducing Python, and Fredrik Lundh's
Introduction to Tkinter, trying to familiarize myself with Python and
GUI design in Tk, and I've run into a puzzling problem. I'm trying to
draw a column of 10 checkboxes, each with a separate variables and
commands. The easy way to do this is to hardcode it, but I was trying
to do something a little more elegant:

self.InUse =[BooleanVar(), BooleanVar(), BooleanVar(), BooleanVar(),
BooleanVar(), BooleanVar(), BooleanVar()]

for i in range(1,11):
for t in range(7):
if(t==0):
Checkbutton(self.frame2, variable =
self.InUse[t]).grid(row= i, column = t)


I figure since I create a separate variable for each checkbutton, the
should be independent of one another. Unfortunately, they are not, and
when I click on one, all become selected/deselected. What am I missing?

Thanks!
 
J

James Stroud

 self.InUse =[BooleanVar(), BooleanVar(), BooleanVar(), BooleanVar(),
BooleanVar(), BooleanVar(), BooleanVar()]
        for i in range(1,11):
            for t in range(7):
                if(t==0):
                    Checkbutton(self.frame2, variable = self.InUse[t]).grid(row= i, column = t)


should this last line read "self.InUse" ?


--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
 
J

James Stroud

 self.InUse =[BooleanVar(), BooleanVar(), BooleanVar(), BooleanVar(),
BooleanVar(), BooleanVar(), BooleanVar()]
        for i in range(1,11):
            for t in range(7):
                if(t==0):
                    Checkbutton(self.frame2, variable =
self.InUse[t]).grid(row= i, column = t)


should this last line read "self.InUse" ?

What I mean to say is that t is always 0 when you assign variable.
--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
 
M

MooMaster

right, I'm basically drawing a table with 3 columns, and I want
checkboxes when we are at column 0. In columns 1-3 I will want Entries
and Labels, but I always want checkboxes @ column 0.
 
M

MooMaster

Uhm....I'm a dunce. Obviously having it only use t[0] is going to make
it cleverly look like I'm using different variables, when in fact I'm
not. Thanks James!
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top