Python Kivy Application Development

Adding better Navigation




In this video, we add another button that will allow us to go from our drawing app back to the "main" screen.

The only major change that is needed here is adding the button in the .kv file, and that's pretty much it!

The python file:

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("main3.kv")

class MainApp(App):
    
    def build(self):
        return presentation

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


		

The .kv file:

#: 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"
	
	FloatLayout:
		Painter
		Button:
			color: 0,1,0,1
			font_size: 25
			size_hint: 0.3,0.2
			text: "Back Home"
			on_release: app.root.current = "main" 
			pos_hint: {"right":1, "top":1}	
		

That's the end of the Kivy series for now. Fore more tutorials, head to the





  • Kivy with Python tutorial for Mobile Application Development Part 1
  • Kivy Widgets and Labels
  • The Kivy .kv Language
  • Kivy .kv Language cont'd
  • Dynamic Resizable Placement
  • Layouts: Float Layout
  • Getting Mouse / Press / Touch Input
  • Simple Drawing Application
  • Builder for loading .kv Files
  • Screen Manager for Multiple Screens
  • Drawing Application with Screen Manager
  • Adding better Navigation