gotta love radio buttons
Ned Batchelder
ned at nedbatchelder.com
Sun Jan 5 13:37:25 EST 2014
On 1/5/14 1:18 PM, eneskristo at gmail.com wrote:
> So, I'm having this radio button issue in tkinter:
> First I assign the IntVar:
> var = []
> while i < self.something:
> var.append(IntVar())
> i += 2
> Later on I use them, but I get this error:
> for r in var:
> helper = var[r].get()
> self.something_else[helper] += 1
> Then, this happens:
> Traceback (most recent call last):
> File "F:\Portable Python 3.2.5.1\App\lib\tkinter\__init__.py", line 1456, in __call__
> return self.func(*args)
> File "----(Not giving this)", line 26, in submit_data
> helper = var[r].get()
> TypeError: list indices must be integers, not IntVar
> I'm willing to give additional info. Thank you in advance.
>
This isn't about radio buttons, it's about how for loops work. I think
you want:
for r in var:
helper = r.get()
The iteration variable in a for loop (r in this case) takes on the
values of the elements of the list, not the indexes of the elements.
--
Ned Batchelder, http://nedbatchelder.com
More information about the Python-list
mailing list