Last active
May 17, 2020 18:21
-
-
Save Olbergx/02f9cf931d2a88acc96eaccebc4d3a02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.app import App | |
from kivy.uix.widget import Widget | |
from kivy.uix.button import Button | |
from random import random | |
from kivy.core.window import Window | |
from kivy.graphics import (Color,Ellipse,Rectangle,Line) | |
class PainterWidget(Widget): | |
def on_touch_down(self,touch): | |
with self.canvas: | |
Color(random(),random(),random(),1) | |
rad = 30 | |
Ellipse(pos = (touch.x - rad/2, touch.y - rad/2), size = (rad,rad)) | |
touch.ud['line'] = Line( points = (touch.x, touch.y), width = 15 ) | |
def on_touch_move(self, touch): | |
touch.ud['line'].points += (touch.x, touch.y) | |
class PaintApp(App): | |
def build(self): | |
parent = Widget() | |
self.painter = PainterWidget() | |
parent.add_widget(self.painter) | |
parent.add_widget(Button(text = 'Очистить', on_press = self.clear_canvas, size = (100,50))) | |
parent.add_widget(Button(text = 'Сохранить', on_press = self.save, size = (100,50), pos = (100,0))) | |
parent.add_widget(Button(text = 'Скриншот', on_press = self.screen, size = (100,50), pos = (200,0))) | |
parent.add_widget(Button(text = 'Выход', on_press = self.exit, size = (100,50), pos = (300,0))) | |
return parent | |
def clear_canvas(self, instance): | |
self.painter.canvas.clear() | |
def save(self, instance): | |
self.painter.size = (Window.size[0],Window.size[1]) | |
self.painter.export_to_png('image.png') | |
def screen(self, instance): | |
Window.screenshot('screenshot.png') | |
def exit(self, instance): | |
App.get_running_app().stop() | |
if __name__ == '__main__': | |
PaintApp().run() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment