【发布时间】:2018-06-15 14:11:34
【问题描述】:
我正在尝试创建一个绘图应用程序。我使用 Kivy Canvas 定义线条的颜色(默认为红色),任务是我需要一个按钮,例如“绿色”,它将颜色更改为绿色。我真的不知道该怎么做。
我尝试的是:
class PainterWidget(Widget):
def on_touch_down(self, touch):
with self.canvas:
self.color = Color(1, 0, 0, 1)
rad = 30
Ellipse(pos = (touch.x, touch.y), size = (rad / 2, rad / 2))
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
def blue(self):
with self.canvas:
self.color = Color(0, 0, 1, 1)
class PaintApp(App):
def build(self):
parent = Widget()
self.painter = PainterWidget()
parent.add_widget(self.painter)
parent.add_widget(Button(text='Blue', size=(50, 50), pos=(0, 480), on_press = PainterWidget.blue))
return parent
但它不起作用。我尝试在 PaintApp 中创建颜色更改方法,执行类似 PainterWidget.color = Color 之类的操作,但它也不起作用。
【问题讨论】: