...
-> код -> Python. AttributeError: 'PainterWidget' object has no attribute 'Color'
PainterWidget
не имеет атрибута Color
class PainterWidget(Widget):
color = (0.2, 0, 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 red(self, instance):
self.painter.color = (1, 0, 0.2, 1)
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):
color = (0.2, 0, 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 build(self):
parent = Widget()
self.painter = PainterWidget()
parent.add_widget(self.painter)
parent.add_widget(Button(text = 'Clear' , on_press = self.clear_canvas, size = (100, 50)))
parent.add_widget(Button(text = 'Save' , on_press = self.save, size = (100, 50), pos = (100, 0)))
parent.add_widget(Button(text = 'Screen', on_press = self.screen, size = (100, 50), pos=(200, 0 )))
def red(self, instance):
self.painter.color = (1, 0, 0.2, 1)
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('mage.png')
def screen(self, instance):
Window.screenshot('screen.png')
if __name__ == '__main__':
PaintApp().run()
Не стал писать в ответе вам полный код. Думал разберетесь.Я учла свои ошибки, и он стал выдавать чёрный экран
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):
color = (0.2, 0, 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 build(self):
parent = Widget()
self.painter = PainterWidget()
parent.add_widget(self.painter)
parent.add_widget(Button(text = 'Clear' , on_press = self.clear_canvas, size = (100, 50)))
parent.add_widget(Button(text = 'Save' , on_press = self.save, size = (100, 50), pos = (100, 0)))
parent.add_widget(Button(text = 'Screen', on_press = self.screen, size = (100, 50), pos=(200, 0 )))
parent.add_widget(Button(text = 'red', on_press = self.red, size = (100, 50), pos=(300, 0 )))
return parent
def red(self, instance):
self.painter.color = (1, 0, 0.2, 1)
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('mage.png')
def screen(self, instance):
Window.screenshot('screen.png')
if __name__ == '__main__':
PaintApp().run()