gotta love radio buttons

Roy Smith roy at panix.com
Sun Jan 5 13:33:12 EST 2014


In article <8dca57e8-8258-4020-9788-987af332b5b2 at googlegroups.com>,
 eneskristo at gmail.com wrote:

I don't use tkinter, but here's what I can figure out from looking at 
your code and http://effbot.org/tkinterbook/variable.htm

> var = []
> while i < self.something:
>     var.append(IntVar())
>     i += 2

At this point, var is a list of IntVar instances.

> for r in var:
>     helper = var[r].get()
>     self.something_else[helper] += 1

You are iterating over the element of var, so each time through the 
loop, r is an IntVar instance.  But, you're using r to index a list in

>     helper = var[r].get()

That's what

> TypeError: list indices must be integers, not IntVar

means.  I suspect what you want is to retrieve the integer value from r, 
and use that as the index:

>     helper = var[r.get()]

but without knowing more about your code, that's just a guess.

At a deeper level, however, there's something that fundamentally doesn't 
make sense here.  You are iterating over the values in var, then using 
each value as an index again.  That's not *wrong*, but it seems unlikely 
to be what you want.



More information about the Python-list mailing list