| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1949 人关注过本帖
标题:用python kivy做了一个画图,但是清屏按钮的动作怎么做?完全没头绪
只看楼主 加入收藏
dtxwz
Rank: 2
等 级:论坛游民
帖 子:79
专家分:45
注 册:2011-9-18
结帖率:100%
收藏
 问题点数:0 回复次数:0 
用python kivy做了一个画图,但是清屏按钮的动作怎么做?完全没头绪
hello.py
from 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
搜索更多相关主题的帖子: from import button Color random 
2018-10-06 16:02
快速回复:用python kivy做了一个画图,但是清屏按钮的动作怎么做?完全没头绪
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.085344 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved