使用pycharm + kivy开发自己的app

kivy 基础工具使用(颜色多变模板,用于画画)

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.graphics import Color, Ellipse, Line
from random import random
from kivy.uix.button import Button


class MyWidgetWidget(Widget):
    def on_touch_down(self, touch):
        color = (random(), random(), random())
        with self.canvas:
            Color(*color)
            touch.ud['Line'] = Line(points=(touch.x, touch.y), width=5)

    def on_touch_move(self, touch):
        touch.ud['Line'].points = touch.ud['Line'].points + [touch.x, touch.y]


class MyPaintApp(App):
    def build(self):
        parent = Widget()
        self.painter = MyWidgetWidget()
        clearbtn = Button(text="Clear")
        clearbtn.bind(on_release=self.clear_canvas)
        parent.add_widget(self.painter)
        parent.add_widget(clearbtn)
        return parent

    def clear_canvas(self, obj):
        self.painter.canvas.clear()


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

操作方法:

1、将py文件放入共享文件夹(VirtuaIDisk)
2、进入VM模拟器
3、进入/media/sf_VirtuaIDisk/ 文件夹复制 main.py
4、将main.py放入/home/kivydev/kivy/accordion/
5、在当前文件夹(/home/kivydev/kivy/accordion/)右击进入 Open Terminal Here
6、修改buildozer.spec文件 默认是Android_apk

(str) Title of your application
title = My Application

(str) Package name
package.name = myapp

(str) Package domain (needed for android/ios packaging)
package.domain = org.test

(str) Source code where the main.py live
source.dir = .

若当前文件夹中没有buildozer.spec文件,便执行 buildozer init

7、完成以上操作后执行:gedit buildozer.spec
8、完成步骤7以后,执行:buildozer android_new debug

环境与虚拟机

链接: https://pan.baidu.com/s/1-HZ-jLtLbPjov3QCu34C6A
提取码: i3kz
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43603846/article/details/123127595