Luno_T
August 8, 2019, 8:53am
1
Hello,
I am trying to learn to use the ControlP5 library in python mode. I am struggling with basic stuff as I have no experience in Java, and I can hardly find proper examples for the python mode.
For instance, when I try to run the following code, the program never goes trough the toogle event function:
add_library("controlP5")
def setup():
global cp5
cp5=ControlP5(this)
size(640,480)
cp5.addToggle("toogle")\
.setPosition(10,10)\
.setSize(50,20)\
.setValue(True)\
.setMode(ControlP5.SWITCH)\
def draw():
background(0)
ellipse (70,20,15,15)
def toogle():
print 'a'
Can you help please?
Best wishes,
Luno
1 Like
Hi,
I found that it is necessary to add when the ‘toogle’ function will be called.
So, try add:
.onClick(toogle)
in your controlP5 code, and also add an input in the function, because it will ask 1 argument as input. You can try:
def toogle(the Value):
So, the code will be like this.
add_library("controlP5")
def setup():
global cp5
cp5=ControlP5(this)
size(640,480)
cp5.addToggle("toogle")\
.setPosition(10,10)\
.setSize(50,20)\
.setValue(True)\
.setMode(ControlP5.SWITCH)\
.onClick(toogle)
def draw():
background(0)
ellipse (70,20,15,15)
def toogle(theValue):
print 'a'
I am still newbie here. But, I hope it can help to solve your problem.
3 Likes
Luno_T
August 8, 2019, 10:18am
3
Dear Rumidita,
Thank you for your reply. The code runs properly now.
Do you have suggestions of references to begin with controlP5 in python mode?
All the best,
Luno
I’ve created this basic ControlP5 Python mode tutorial .
Once you understand the fundamental differences of using ControlP5 in Python mode, translating the Java examples shouldn’t be too difficult.
4 Likes
Luno_T
August 9, 2019, 6:41am
5
Dear tabreturn,
Many thanks for your tutorial. It is definitely what is needed to get started.
Best,
Luno