Creating Buttons referenced like an array

You have to keep in mind that you are not really dealing with an array
here. You are dealing with a sequence. The "array" that you are trying to
assign to doesn't exist. And unless you've done something to ensure that
'btn' references a sequence, that sequence doesn't exist either.

   b[0] = x

will fail because you are *referencing* b and it is not yet defined.

You need something like:

   b = # b is an empty sequence
   b.append('foo') # append 'foo' to b; this is the moral equivalent of "
b[0] = 'foo' "

You could also use the insert() method, but beware of what Python does when
you insert at a point beyond the current range of a sequence.

So my guess is that you need something like:

   btn = # an empty sequence we can append to

   while whatever:
      # Append next button to sequence
       btn.append( wxButton(self, -1, "Hello",(height*22,0),(width,22)) )

Think sequences, tuples, lists. Think Lisp. No arrays (something of a
pain in various circumstances, I agree). Python does support arrays via
the class library, but not really to my liking. Someone should do a nice
general and efficient array class that supports arrays of arbitrary
objects.

···

--------------------------------------
Gary H. Merrill
Director and Principal Scientist, New Applications
Data Exploration Sciences
GlaxoSmithKline Inc.
(919) 483-8456

                      "Mike Wagman"
                      <mwagman@charter.net>
                                                                                                                               
                                                     To: "wxpython list" <wxPython-users@lists.wxwindows.org>
                      05-Aug-2003 22:50
                      Please respond to cc:
                      wxPython-users@lists.wx Subject: Re: [wxPython-users] Creating Buttons referenced like an array
                      windows.org
                                                                                                                               
Perhaps my problem is in creation of the first button.

i is currently 0.

btn[i] = wxButton(self, -1, "Hello",(height*22,0),(width,22))
TypeError: object doesn't support item assignment

On Tue, 2003-08-05 at 12:05, Robin Dunn wrote:

Mike Wagman wrote:
> Is there a way to create buttons with a command like.
>
> btn[1]= wxButton(self, -1, MIList[i],(height*22,0),(width,22))
>
> I keep getting erros related to the creation of the button,

What are the errors? What is btn? What is MIList[i]? We can't help
you unless you are unambiguous and give all the details.

> and I am not
> sure how to create an array of buttons.

The same way you would create a collection of any other object in
Python. Create the object and append it to a list.

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

Just for interest's sake, what are you trying to do that can only be
done with what you define as an "array" and not with a Python sequence
type?

···

On Wed, 2003-08-06 at 15:38, gary.h.merrill@gsk.com wrote:

Think sequences, tuples, lists. Think Lisp. No arrays (something of a
pain in various circumstances, I agree). Python does support arrays via
the class library, but not really to my liking. Someone should do a nice
general and efficient array class that supports arrays of arbitrary
objects.

--
charl p. botha http://cpbotha.net/ http://visualisation.tudelft.nl/