I would like to update data using onClick button, so I try using an item from controlP5 library. I hope when I click the button, the ‘old’ data will be changed by the ‘new’ data. But, it seems still hold the ‘old’ data.
Here is my code.
add_library('controlP5')
def updateData(v):
data = 'new'
def setup():
global data
size(200,200)
frameRate(5)
data = 'old'
cp5 = ControlP5(this)
cp5.addBang('Update').setPosition(50,50)\
.setSize(60,30)\
.onClick(updateData)\
.getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
def draw():
print(data)
When I try to run the program, it prints the ‘old’ data every time, even I click on the button.
Hope someone can help.