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): Code:
createButton([0.25,0.8],'button01Off.jpg', 'button01On.jpg', 'button1', 2) But now I want to define onbuttondown events, but this does not work! If I write: Code:
def onButton(obj,state): So I want to write: Code:
def onButton(obj,state): 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... |
Your createButton function should return the button object and you should save the object in a global variable with the name you want. For example:
Code:
def createButton(self, position, pictureOff, pictureOn, name, szene): |
Hi,
thanks for your answer. But this does not work. :mad: For example: I've got this class: Code:
import viz and this start.py Code:
import viz In my example, the button got the name 'testbutton'. But then, I've got the error message: 'Button' object has no attribute 'testbutton' What is wrong?? :confused::eek: |
You need to assign the return value of the createButton function to a variable:
Code:
import viz |
Yes it works!
Thank you very much.... |
All times are GMT -7. The time now is 10:50 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC