Sunday, July 4, 2021

kivy 7 draw with python


#main.py
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
import random
from kivy.graphics.vertex_instructions import (Rectangle, Ellipse, Line)
from kivy.graphics.context_instructions import Color
from kivy.properties import ListProperty, ObjectProperty

class ScatterTextWidget(BoxLayout):
    text_colour = ListProperty([1, 0, 0, 1])

    def __init__(self, **kwargs):
        super(ScatterTextWidget, self).__init__(**kwargs)

        with self.canvas.after:
            Color(0, 1, 0, 1)
            Rectangle(pos=(0, 100), size=(300, 100))
            Ellipse(pos=(0, 400), size=(300, 100))
            Line(points=[0, 0, 500, 600, 400, 300], close=True, width=3)

    def change_label_colour(self, *args):
        colour = [random.random() for i in [0,1,2]] + [1]
        print(colour)
        self.text_colour = colour

class TutorialApp(App):
    def build(self):
        return ScatterTextWidget()

TutorialApp().run()

reference:

No comments:

Post a Comment