【发布时间】:2017-09-28 00:36:23
【问题描述】:
我刚开始在我的应用程序中使用 Kivy,但遇到了问题。 我尝试清理我的画布,但我无法将按钮与画布相关联
class DrawInput(Widget):
def on_touch_down(self, touch):
print(touch)
with self.canvas:
touch.ud["line"] = Line(points=(touch.x, touch.y), width=100)
def on_touch_move(self, touch):
#print(touch)
touch.ud["line"].points += (touch.x, touch.y)
def on_touch_up(self, touch):
self.export_to_png("roy.png")
print("RELEASED!", touch)
def cleaner(self):
self.canvas.clear()
class AnotherScreen(Screen):
pass
presentation = Builder.load_file("main2.kv")
class MainApp(App):
def build(self):
return presentation
def clear_canvas(self, obj):
MainApp().run()
这里是main2.kv
GridLayout:
cols: 2
Button:
on_release: root.change_text()
color: 0,1,0,1
font_size: 25
size_hint: 0.3,0.2
text: root.random_number
pos_hint: {"right":1, "top":1}
DrawInput
Button:
on_release: root.clean()
color: 0,1,0,1
font_size: 25
size_hint: 0.3,0.2
text: "Clear"
我的问题是我需要从其他类调用 Clean Method,但是当我尝试它时它说我需要发送“Self”,有人可以帮助我吗? 只是试图清理与 DrawInput 相关的画布
【问题讨论】:
-
你实现了两种方法,即cleaner和clear_canvas。您要调用哪种方法?您的 clear_canvas 为空(缺少代码)。