【发布时间】:2017-12-06 12:39:34
【问题描述】:
我正在创建一个简单的绘图应用程序,我想在其中添加一个撤消按钮。到目前为止,我尝试过的是:
class DrawScreen(Screen):
r = NumericProperty(0)
g = NumericProperty(0)
b = NumericProperty(0)
brush_width = NumericProperty(2)
def on_touch_down(self, touch):
self.slider = self.ids.slider
if self.slider.collide_point(touch.x, touch.y):
self.brush_width = self.slider.value
else:
self.undo = [touch.x, touch.y]
with self.canvas.before:
Color(self.r, self.g, self.b)
touch.ud["line"] = Line(points=self.undo, width=self.brush_width)
return super(DrawScreen, self).on_touch_down(touch)
def on_touch_move(self, touch):
if self.slider.collide_point(touch.x, touch.y):
self.brush_width = self.slider.value
else:
try:
self.undo += [touch.x, touch.y]
touch.ud["line"].points = self.undo
except:
pass
return super(DrawScreen, self).on_touch_move(touch)
def color(self, r, g, b):
self.r = r
self.g = g
self.b = b
def undo_draw(self):
self.undo = []
此撤消按钮会清除列表,但不会以任何方式影响画布,也不会删除任何行。解决此问题的适当方法是什么?
【问题讨论】:
标签: python kivy kivy-language