I am trying to create wx objects dynamically, for example:
List = [(button),(textctrl),(button),(checkbox)]
bindex,tindex,cindex = 1
for item in List:
if item == 'button':
b%s = wx.Button(self,-1,'') % bindex
bindex += 1elif item == 'textctrl':
t%s = wx.TextCtrl(self,-1,'') % tindex
tindex += 1else:
c%s = wx.CheckBox(self,-1) % cindex
cindex += 1
I get "SyntaxError: can't assign to operator". Maybe you
know what I'm
trying to do is possible, thanks for any hints.
I'm guessing "what you're trying to do" is end up with a set
of objects bound to b1, t1, b2 and c1. You *can* do this using
exec, but I've got to wonder why you'd want to, given that you'd
have to jump through the same exec hoops to use them. Much
better to stick them in dicts:
b = {}
...
if item == 'button':
b[bindex] = wx.Button(self,-1,'')
bindex += 1
or arrays:
b = []
...
if item == 'button':
b.append(wx.Button(self,-1,''))