I try to define a function with a variable name.
Names are retrieved from a database. For every name I want to define a button and have separate handling:
title=['BNL','CE']
for i in range(0,len(title)):
panelvpu.add(Button(title[i]))
for i in range(0,len(title)):
eval('def onButtonClick'+title[i]+'(self, event):')
eval(' Window.alert("Yes")')
The button definition is ok, but the handling of the event in the defined function gives an error
im1 SyntaxError: at index 4 in "def onMenu1Item1(self):
Window.alert("Item 1 selected")": expected ';', got 'onMenu1Item1'
After feedback I changed this to
title=['BNL','CE']
for t in title : panelvpu.add(Button(t))
for t in title:
def_code = "print t"
exec(def_code)
Just to get the feeling; under python this works fine. But I use pyjamas and the last code does rais the error stating
im1 TypeError: iter is undefined
It appears that pyjamas is not supporting eval() and exec() yet.
Richard