用python kivy做了一个画图,但是清屏按钮的动作怎么做?完全没头绪
hello.pyfrom kivy.app import App
from kivy.uix.button import Button
from kivy.lang import Builder
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.widget import Widget
from kivy.graphics import Line,Canvas,Color
from kivy.uix.screenmanager import ScreenManager, Screen,FadeTransition
from random import random
class Draw(Widget):
def on_touch_down(self,touch):
color = (random(),random(),random())
with self.canvas:
Color(*color)
touch.ud["line"] = Line(points=(touch.x,touch.y))
def on_touch_move(self,touch):
touch.ud["line"].points +=(touch.x,touch.y)
class MainScreen(Screen):
pass
class AnotherScreen(Screen):
pass
class Sm(ScreenManager):
pass
kv = Builder.load_file("main.kv")
class TestApp(App):
def build(self):
return kv
TestApp().run()
main.kv
#: import FadeTransition kivy.uix.screenmanager.FadeTransition
Sm:
transition:FadeTransition()
MainScreen:
AnotherScreen:
<MainScreen>:
name:"main"
Button:
on_release:app.root.current = "other"
text:"next"
font_size:50
<AnotherScreen>:
name:"other"
Draw
Button:
on_release:app.root.current = "main"
text:"back"
font_size:40
size_hint:0.3,0.2
pos_hint:{"right":1,"bottom":1}
color:0,1,0,1
Button:
on_release:
text:"clear"
font_size:40
size_hint:0.3,0.2
pos_hint:{"right":1,"top":1}
color:0,1,0,1