【发布时间】:2019-05-23 01:23:53
【问题描述】:
无法使用 Kivy 移动小部件
我想移动一个矩形并遵循 youtube 中使用的代码(亚历山大泰勒的 kivy 速成课程 11)。代码后矩形出现在屏幕上但不移动
python 代码
class CRect:
velocity = ListProperty([20, 10])
def __init__(self, **kwargs):
super(CRect, self).__init__(**kwargs)
Clock.schedule_interval(self.update, 1/60)
def update(self):
self.x += self.velocity[0]
self.y += self.velocity[1]
if self.x < 0 or (self.x+self.width) > Window.width:
self.velocity[0] *= -1
if self.y < 0 or (self.y+self.height) > Window.height:
self.velocity[1] *= -1
if __name__ == '__main__':
RRApp().run()
kv码
<DemoCreator>:
CRect:
canvas:
Color:
rgba: 1,0,0,1
Rectangle:
pos: 100,0
size: 40,40
<CRect@Widget>
没有错误消息。但不能移动小部件
【问题讨论】:
标签: python user-interface kivy