Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #63210

Re: gotta love radio buttons

Date 2014-01-05 10:38 -0800
From Gary Herron <gary.herron@islandtraining.com>
Subject Re: gotta love radio buttons
References <8dca57e8-8258-4020-9788-987af332b5b2@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.4957.1388947598.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 01/05/2014 10:18 AM, eneskristo@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.


These two lines

for r in var:
     helper = var[r].get()

are being redundant.

The loop returns elements from the list (one-by-one).   Also  var[r] 
attempts to return an element from the list (indexed by r -- expected to 
be an integer).

Either of these remove the redundancy (but the first is more Pythonic)

   for r in var:
       helper = r.get()

or

   for i in range(len(var)):
      helper = var[i].get()

Gary Herron

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

gotta love radio buttons eneskristo@gmail.com - 2014-01-05 10:18 -0800
  Re: gotta love radio buttons Roy Smith <roy@panix.com> - 2014-01-05 13:33 -0500
  Re: gotta love radio buttons Ned Batchelder <ned@nedbatchelder.com> - 2014-01-05 13:37 -0500
  Re: gotta love radio buttons Kev Dwyer <kevin.p.dwyer@gmail.com> - 2014-01-05 18:40 +0000
  Re: gotta love radio buttons eneskristo@gmail.com - 2014-01-05 10:47 -0800
    Re: gotta love radio buttons Gary Herron <gary.herron@islandtraining.com> - 2014-01-05 11:51 -0800
  Re: gotta love radio buttons Gary Herron <gary.herron@islandtraining.com> - 2014-01-05 10:38 -0800

csiph-web