I found this similar question:
How do I change the color of my widget in Kivy at run time?
I'm using a similar approach to try and change the colour of widgets as I drag and move them around.
class GraphNode(Widget):
r = NumericProperty(1.0)
def __init__(self, **kwargs):
self.size= [50,50]
self.pos = [175,125]
super(GraphNode, self).__init__(**kwargs)
def on_touch_down(self, touch):
if self.collide_point(*touch.pos):
if touch.grab_current == None:
self.r = 0.6
touch.grab(self)
return True
return super(GraphNode, self).on_touch_down(touch)
def on_touch_move(self, touch):
if touch.grab_current is self:
self.pos=[touch.x-25,touch.y-25]
# now we only handle moves which we have grabbed
def on_touch_up(self, touch):
if touch.grab_current is self:
touch.ungrab(self)
self.r = 1.0
# and finish up here
def onTouchMove(self, touch):
if self.collide_point(touch.x, touch.y):
self.pos=[touch.x-25, touch.y-25]
pass
I'm trying to update the numeric property to change the color, using this (kv) file:
#:kivy 1.0.9
<GraphInterface>:
node: graph_node
GraphNode:
id: graph_node
center: self.parent.center
<GraphApp>:
canvas:
<GraphNode>:
size: 50, 50
canvas:
Ellipse:
pos: self.pos
size: self.size
Color:
rgba: (root.r,1,1,1)
<GraphEdge>:
size: 10, 10
canvas:
However the colours do not change when I grab them. If I don't change the colour in the on_touch_drop() method, then i can spawn nodes with the new colour. Any idea how to fix this?