1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

var button question

Posted by HG Lewes on Jul 30, 2007

Quick Question:

(From Reference)

"The command parameter for buttons is the name of a
command in your script to call when the button is
pressed."
 
. What is meant by "a command" in your script
 
I have tried calling a function
with this:
var("hello()", BUTTON)
 
def hello():
    print "Hello World"
but I just get errors when I press the button, no matter what I try. I tried a def within a class (method) also..

Any help would be greatly appreciated, I fear there is an obvious answer I am missing ;)

H. G.


 
Posted by Tom De Smedt on Aug 03, 2007

Hi HG,

The solution is fairly simple: omit the () from "hello()":

var("hello", BUTTON)
When you use hello() you are calling the hello-command (e.g. executing its contents). The var() command just wants the name of the hello-command ("hello") so it can call by itself when you press the button.



Posted by Kkosmos on Feb 12, 2008

Hey, I got a similar problem:

the code

def rectangles():
    print "set to rectangles"
var ("rectangles",BUTTON)
produces a nice button labeled 'rectangles'. When I press it, there is no 'set to rectangles' message but something telling me:

…TypeError: 'str' object is not callable

I fiddled around a lot, but can not get rid of this error, or get the button to work. I can turn it into a slider though by changing the above code to
def rectangles():
    print "set to rectangles"
var ("rectangles",rectangles(),BUTTON)
In this case, the slider, when touched, does what the button is supposed to do, but still is a slider.

Help would be great. Kkosmos



Posted by Esteban on Feb 12, 2008

try by putting the var declaration before the actual function declaration, like this:

var ("rectangles",BUTTON)
def rectangles():
    print "set to rectangles"