【发布时间】:2018-07-17 15:46:55
【问题描述】:
这是一个可以在他的计算机上运行的整体代码
main.py
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
class SnakeGame(FloatLayout):
pass
class SnakeGameApp(App):
def build(self):
return SnakeGame()
if __name__ == '__main__':
SnakeGameApp().run()
snakegame.kv
#: include snake.kv
<SnakeGame>:
Snake:
pos: 300, 300
snake.py
# Control object for the Snake view object in snake.kv
class Snake(Widget):
def move(self):
print("Moving")
snake.kv
#: import Widget kivy.uix.widget.Widget
<Snake@Widget>:
size_hint: None, None
size: 15, 15
canvas:
Color:
rgba: 1, 0, 0, 1
Rectangle:
pos: self.pos
size: self.size
on_touch_down: self.move() # There is an error here: Snake object has
# no attribute move.
# How can i connect to the snake.py
# file here the same it was automatically
# connecting the SnakeGame class in the main.py
# file with the SnakeGame class in the snakegame.py file
# ???
snake.kv 文件有错误:Snake 对象没有属性 move。 我如何在这里连接到snake.py文件,就像它自动将main.py文件中的SnakeGame类与snakegame.py文件中的SnakeGame类一样???
非常感谢。
我已经进行了广泛的谷歌搜索,但找不到任何有用的东西。
【问题讨论】:
标签: python class module kivy communication