简体   繁体   English

在 Android 上运行 Kivy

[英]Run Kivy on Android

So, I can run kivy example files (like pong) on my Android but I can't run my own app , it just saying "Hello World!".所以,我可以在我的 Android 上运行 kivy 示例文件(如 pong),但我不能运行我自己的应用程序,它只是说“Hello World!”。

I don't understand, if someone can help me.我不明白,如果有人可以帮助我。

This is my Python code :这是我的 Python 代码:

import kivy
from kivy.app import App
from kivy.config import Config
from kivy.uix.label import Label
from kivy.uix.widget import Widget

Config.set('graphics','width','360')
Config.set('graphics','height','640')

class Mot(Widget):
    def mot(self):
        test = 0

    def bouger(self):



class WorDown(App):
    def build(self):
        return Mot()

if __name__ == '__main__':
    WorDown().run()

Next my Kivy code :接下来我的 Kivy 代码:

#:kivy 1.0

<Mot>:
    Widget:
        canvas:
            Color:
                rgb: (255, 0, 0)
            Rectangle:
                size: (360,640)
                pos: self.pos

    Label:
        text: 'WorDown'
        center_x: root.width / 2

And my android.txt :我的 android.txt :

title=WorDown
author=pito
orientation=portrait

So I put these three files in a folder in the Kivy folder of my Android Phone.所以我把这三个文件放在我的 Android 手机 Kivy 文件夹中的一个文件夹中。 And when I run Kivy launcher, and click on "WorDown", Kivy Launcher runs the app but crashes just 3 seconds after...当我运行 Kivy 启动器并单击“WorDown”时,Kivy 启动器运行该应用程序但仅在 3 秒后崩溃...

And I don't understand why, because on my Windows Computer, it runs very well!我不明白为什么,因为在我的 Windows 计算机上,它运行得很好!

Please look at the python code you included.请查看您包含的python代码。 In class Mot you haveclass Mot您有

def bouger(self):

but nothing in the function body.但函数体中没有任何内容。

Do you really don't have anything in the body?你的身体真的没有任何东西吗? Your code shouldn't even run on your computer then, so I guess you just didn't post everything.那时您的代码甚至不应该在您的计算机上运行,​​所以我猜您只是没有发布所有内容。

If you are sure that the code in this function is not causing the crash, just write "pass" in the function body, so that it doesn't confuse other readers.如果您确定该函数中的代码不是导致崩溃的,只需在函数体中写上“pass”,以免其他读者混淆。

you could follow the code main.py你可以按照代码main.py

import kivy
from kivy.uix.label import Label
from kivy.app import App
class MyApp(App):
    def build(self):
        return Label(text='WorDown' )

if __name__=="__main__":
    MyApp().run()

在删除 7 行和 8 行代码后尝试运行您的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM