View Single Post
  #1  
Old 07-12-2009, 06:22 AM
lilio lilio is offline
Member
 
Join Date: May 2009
Posts: 11
Question Call objects created within definitions

Hi,

I want to create buttons within a definition. Something like that:

Code:
def createButton(self, position, pictureOff, pictureOn, name, szene):
		self.Position = position
		self.PictureOff = pictureOff
		self.PictureOn = pictureOn
		self.Name = name
		self.Szene = szene
		
		name = viz.add(viz.BUTTON, scene=szene)
		name.translate(position[0],position[1])
		name.uppicture(pictureOff)
		name.downpicture(pictureOn)
		name.setScale(12,3.6)
And afterthat I call the def like this way:
Code:
createButton([0.25,0.8],'button01Off.jpg', 'button01On.jpg', 'button1', 2)
So I want to set the button-name manually. This works fine.

But now I want to define onbuttondown events, but this does not work!

If I write:

Code:
def onButton(obj,state):
 if obj == viz.VizButtonLabel(5):
   viz.scene( 2 )
then it works. But this isn't a very good solution. Because if I create more and more objects, I had to change the number of the buttonlabel.

So I want to write:

Code:
def onButton(obj,state):
 if obj == button1:
   viz.scene( 2 )

But this does not work! I get the error message: global name 'button1' is not defined.


I don't know how to solve this problem.

I only want to create a lot of buttons and want to set the name of the button over a parameter. And afterthat I want to check the onbuttondown event via the buttonname.

Thanks for all your answers...
Reply With Quote