<p><code>Bezier</code>没有<code>width</code>属性,但是<code>Line</code>有。因此,您可以设置<code>width</code>的动画。一种简单的方法是设置一个保持宽度的<code>NumericProperty</code>的动画。下面是代码的一个修改版本,它可以:</p>
<pre><code>from kivy.animation import Animation
from kivy.app import App
from kivy.clock import Clock
from kivy.properties import NumericProperty
from kivy.uix.widget import Widget
from kivy.graphics import *
class MyLayout(Widget):
line_width = NumericProperty(12)
def __init__(self):
super(MyLayout, self).__init__()
with self.canvas:
self.L=Bezier(points=[200,450,500,300,600,150],width=self.line_width)
self.k=Line (bezier=[100,350,400,200,500,50 ],width=self.line_width)
def on_line_width(self, instance, new_width):
self.k.width = new_width
class MyApp(App):
def build(self):
Clock.schedule_once(self.anim)
return MyLayout()
def anim(self, dt):
a = Animation(line_width=3)
a.start(self.root)
if __name__=="__main__":
MyApp().run()
</code></pre>
<p>如果您在<code>kv</code>中构建<code>Line</code>,那么您甚至不需要<code>on_line_width()</code>方法,因为kivy将为您进行绑定</p>