• Home
  • About
    • 朱智博在Github上的Blog photo

      朱智博在Github上的Blog

      朱智博,朱智博的博客,zhuio,zhuio.github.io,

    • Learn More
    • Email
    • Github
    • Weibo
  • Posts
    • All Posts
    • All Tags
  • Projects

kivytutor10

25 Jan 2017

Reading time ~1 minute

屏幕绘图应用程序管理器

本教程涵盖了我们已经学到的东西的啮合与屏幕经理与我们之前建立的绘图应用程序。

python文件:

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

from kivy.uix.widget import Widget
from kivy.graphics import Line


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 ScreenManagement(ScreenManager):
    pass


presentation = Builder.load_file("main2.kv")

class MainApp(App):

    def build(self):
        return presentation

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

    

以上,唯一的重大变化(除了kivy加载文件对我来说,你可能会或可能不会做)的“画家”类。 这里的代码包含了 绘图应用教程 。

的。 kv文件:

#: import FadeTransition kivy.uix.screenmanager.FadeTransition

ScreenManagement:
	transition: FadeTransition()
	MainScreen:
	AnotherScreen:

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

<AnotherScreen>:
	name: "other"
	Painter		

  

在我们的。 kv文件,唯一的变化是现在,而不是一个按钮,我们称“画家”,这是叫我们写的画家类。

我们的结果:



kivy Share Tweet +1