0
蟒蛇2.7.x kivy 1.9.0Kivy傍教程語法錯誤:無效的語法
我剛剛開始接觸Kivy,通過傍教程去。事情進展順利,但現在我得到了一個非常簡單的錯誤。我無法弄清楚什麼是錯的。
我得到的錯誤是:
File: "C:\Users\toreilly\mystuff\kivypong.py" \n
def update(self, dt):
^
SyntaxError: invalid syntax
的代碼是在這裏:
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import NumericProperty, ReferenceListProperty, \
ObjectProperty
from kivy.vector import Vector
from kivy.clock import Clock
from random import randint
class PongBall(Widget):
velocity_x = NumericProperty(0)
velocity_y = NumericProperty(0)
velocity = ReferenceListProperty(velocity_x, velocity_y)
def move(self):
self.pos = Vector(*self.velocity) + self.pos
class PongGame(Widget):
ball = ObjectProperty(None)
def serve_ball(self):
self.ball.center = self.center
self.ball.velocity = Vector(4,0).rotate(randint(0,360)
def update(self, dt):
self.ball.move()
#bounce off top and bottom
if (self.ball.y < 0) or (self.ball.top > self.height):
self.ball.velocity_y *= -1
#bounce off left and right
if (self.ball.x < 0) or (self.ball.right > self.width):
self.ball.velocity_x *= -1
class PongApp(App):
def build(self):
game = PongGame()
game.serve_ball()
Clock.schedule_interval(game.update, 1.0/60.0)
return game
if __name__ == '__main__':
PongApp().run()
我將不勝感激任何和所有的指導。謝謝。