[英]Kivy: Updating colour of widgets in real time
我發現了類似的問題:
我使用類似的方法來嘗試在拖動和移動小部件時更改其顏色。
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
我正在嘗試使用以下(kv)文件更新numeric屬性以更改顏色:
#: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:
但是,當我抓住它們時顏色不會改變。 如果我沒有在on_touch_drop()方法中更改顏色,則可以使用新顏色生成節點。 任何想法如何解決這個問題?
看起來您的代碼可能工作正常,但是Color指令排在其他所有指令之后,因此根本不受影響。 您是要把它放在橢圓形前面嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.