简体   繁体   中英

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!".

I don't understand, if someone can help me.

This is my Python code :

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 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 :

title=WorDown
author=pito
orientation=portrait

So I put these three files in a folder in the Kivy folder of my Android Phone. And when I run Kivy launcher, and click on "WorDown", Kivy Launcher runs the app but crashes just 3 seconds after...

And I don't understand why, because on my Windows Computer, it runs very well!

Please look at the python code you included. In class Mot you have

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.

you could follow the code 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 行代码后尝试运行您的代码。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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