如何在python中通过鼠标位置值绘制椭圆来开发kivy中的绘画应用程序?

2024-06-06 21:05:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我想开发一个绘画应用程序,创建椭圆或圆形作为鼠标在画布上移动


Tags: 应用程序画布圆形鼠标椭圆绘画
1条回答
网友
1楼 · 发布于 2024-06-06 21:05:08

关于如何在kivy的网站上制作绘图应用程序,有很多很好的例子。
看看Drawing app in kivy

网站上的一个例子。你知道吗

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


class MyPaintWidget(Widget):

    def on_touch_down(self, touch):
        with self.canvas:
            Color(1, 1, 0)
            d = 30.
            Ellipse(pos=(touch.x - d / 2, touch.y - d / 2), size=(d, d))
            touch.ud['line'] = Line(points=(touch.x, touch.y))

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


class MyPaintApp(App):

    def build(self):
        return MyPaintWidget()


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

相关问题 更多 >