首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何将任意python文件连接到任意kivy文件?

如何将任意python文件连接到任意kivy文件?
EN

Stack Overflow用户
提问于 2018-07-17 23:46:56
回答 1查看 199关注 0票数 0

下面是用户可以在自己的计算机上运行的全部代码

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对象没有属性移动。如何在这里连接到snake.py文件,就像它自动连接main.py文件中的SnakeGame类和snakegame.py文件中的SnakeGame类一样?

非常感谢。

我已经做了大量的谷歌搜索,但找不到任何有帮助的东西。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51385553

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档