Nerd For Tech
Published in

Nerd For Tech

How to Create a Back Button in Kivy

I created a back button by first setting up an __init__ function in my App class and then having self.previous_screen that would hold the name of the previous screen. I used <Screen> in the .kv file to make this apply to all the screens. Then whenever I created a back button, I would reference app.previous_screen.

The file:

from kivy.uix.screenmanager import Screen, ScreenManager
from import App, Builder


class Home(Screen):
class User(Screen):

class RootWidget(ScreenManager):

class Test(App):
def __init__(self, **kwargs):
super(Test, self).__init__(**kwargs)
self.previous_screen = ""

def build(self):
return RootWidget()

if __name__ == '__main__':

I used <Screen> and the on_leave property to make sure that the self.previous_screen updated after every screen change.

on_leave: app.previous_screen =

name: "home_screen"
cols: 1
padding: 10
text: "To User Screen"
on_release: root.manager.current = "user_screen"

name: "user_screen"
cols: 1
padding: 10
text: "Back"
on_release: root.manager.current = app.previous_screen





NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit

Recommended from Medium

You Don’t Need a Bazooka to Hunt Rabbits

Kotlin in the real world

Organizations often use the terms ‘Quality Assurance’ (QA) vs ‘Quality Control’ (QC)…

Non-Preemptive Priority Scheduling


Things to consider for mobile app testing

Essential guide to effective goal setting for your mobile development project

Building AWS Infra with Terraform 2

Prepare Skeleton of our Micro-services and Setup Eureka Service Application

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


I am a librarian and new computer programmer creating an app with Python and Kivy to document the plants in my garden.

More from Medium

Instabot get all the followers of an Instagram account with Python

How to export excel properly with Flask and Ajax Call

Build Your First Transliterator Text Editor with Python Tkinter

Backend with Python: