2017-03-01 87 views
0

我创建了一个简单的绘图应用程序。我得到这个错误: “pythonw.exe已停止工作” 我不明白为什么它表明我这个错误,我很乐意帮助:)Kivy简单绘图应用程序

我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 code(叫做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} 

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

回答

0

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

也尝试从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] 
+0

我不认为这是因为当我创建了一个非常简单的应用程序谁使用ScreenManagment我得到了同样的错误。我在下一个答案中写了应用程序。 –

+0

@ShaharBitan你从cmd运行它,而不是从闲置? – EL3PHANTEN

+0

是的,它不工作 –