Код:
from tkinter import *
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from random import random
from kivy.core.window import Window
from kivy.graphics import (Color, Ellipse, Rectangle, Line)
from kivy.uix.gridlayout import GridLayout
Window.clearcolor = (1, 1, 1, 1)
class PainterWidget(Widget):
color = (1, 1, 1, 1)
def on_touch_down(self, touch):
with self.canvas:
Color(rgba=self.color)
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 edit_click():
root = Widget(fg=(0, 0, 0, 1))
main_menu = Menu()
main_menu.add_cascade(label="color")
root.config(menu=main_menu)
root.mainloop()
def build(self):
parent = Widget()
self.painter = PainterWidget()
parent.add_widget(self.painter)
parent.add_widget(Button(text = '', on_press = self.blue,
background_color = [0.2, 0, 1, 1],
size = (100, 50), pos=(0, 0),
background_normal = ''))
parent.add_widget(Button(text = '', on_press = self.red,
background_color = [1, 0, 0.2, 1],
size = (100, 50), pos=(200, 0),
background_normal = ''))
parent.add_widget(Button(text = '', on_press = self.white,
background_color = [1, 1, 1, 1],
size = (100, 50), pos=(100, 0),
background_normal = ''))
parent.add_widget(Button(text = '', on_press = self.black,
background_color = [0, 0, 0, 1],
size = (100, 50), pos=(300, 0),
background_normal = ''))
return parent
def black(self, instance):
self.painter.color = (0, 0, 0, 1)
def red(self, instance):
self.painter.color = (1, 0, 0.2, 1)
def blue(self, instance):
self.painter.color = (0.2, 0, 1, 1)
def white(self, instance):
self.painter.color = (1, 1, 1, 1)
if __name__ == '__main__':
PaintApp().run()