Develop your own app using pycharm + kivy

Use of kivy basic tools (color-changing templates for painting)

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()

How to operate:

1. Put the py file into the shared folder (VirtuaIDisk)
2. Enter the VM simulator
3. Enter the /media/sf_VirtuaIDisk/ folder and copy main.py
4. Put main.py into /home/kivydev/kivy/accordion/
5. Right-click on the current folder (/home/kivydev/kivy/accordion/) to enter Open Terminal Here
6. Modify the buildozer.spec file and the default is 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 = .

If there is no buildozer.spec file in the current folder, execute buildozer init

7. After completing the above operations, execute: gedit buildozer.spec
8. After completing step 7, execute: buildozer android_new debug

Environment and virtual machines

Link: https://pan.baidu.com/s/1-HZ-jLtLbPjov3QCu34C6A
Extraction code: i3kz
Insert image description here

Guess you like

Origin blog.csdn.net/weixin_43603846/article/details/123127595