Kivy简单的绘图应用程序

时间:2017-03-01 12:46:17

标签: kivy kivy-language

我创建了一个简单的绘图应用程序。我收到了这个错误:  " pythonw.exe已停止工作" 我不明白为什么它会告诉我这个错误,我很乐意帮忙:)。

我的kivy代码:

from kivy.app import App
# kivy.require("1.8.0")
from kivy.uix.widget import Widget
from kivy.graphics import Line
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition

class Painter(Widget):
    def on_touch_down(self, touch):
        with self.canvas:
            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 ScreenManegmant(ScreenManager):
    pass

presention = Builder.load_file("main1.kv")



class SimpleKivy(App):
    def build(self):
        return presention

if __name__ =="__main__":
    SimpleKivy().run()

我的kv.language代码(名为main1.kv):

#: import FadeTransition kivy.uix.screenmanager.FadeTransition

ScreenManegmant:
    transition: FadeTransition()
    MainScreen:
    AnotherScreen:

<MainScreen>:
    name: "main"
    Button:
        on_release: app.root.current= "other"
        text: "next"
        font_size: 50



<AnotherScreen>:
    name: "other"

    FloatLayout:
        Painter
        Button:
            on_release: app.root.current= "main"
            text: "back"
            font_size: 25
            color: 0,1,0,1
            size_hint: 0.3,0.2
            pos_hint: {"left":1,"up":1}

有人知道我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

此应用适用于我。如果我开始绘制过渡,则会出现错误,因为在创建touch.ud["line"]之前触摸将全部移动。要解决此问题,您可以检查on_touch_move方法中是否存在密钥,然后创建它。

还尝试从cmd运行它而不是空闲。

class Painter(Widget):
    def on_touch_down(self, touch):
        with self.canvas:
            touch.ud["line"] = Line(points=(touch.x,touch.y))

    def on_touch_move(self, touch):
        if "line" not in touch.ud:
            touch.ud["line"] = Line(points=(touch.x,touch.y))
        touch.ud["line"].points += [touch.x,touch.y]