#clock.py
from kivy.base import runTouchApp
from kivy.lang import Builder
from kivy.uix.widget import Widget
from kivy.clock import Clock
from kivy.properties import ListProperty
from kivy.core.window import Window
Builder.load_string('''
<Root>:
ClockRect:
pos: 300, 300
<ClockRect>:
size: 200, 100
canvas:
Color:
rgba: 1, 0, 0, 1
Rectangle:
pos: self.pos
size: self.size
''')
class Root(Widget):
pass
class ClockRect(Widget):
velocity = ListProperty([10, 15])
def __init__(self, **kargs):
super(ClockRect, self).__init__(**kargs)
Clock.schedule_interval(self.update, 1/60)
def update(self, *args):
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
runTouchApp(Root())
reference:
No comments:
Post a Comment