title: Kivy: how do I clear the changes on a screen if they were not saved
body: <p>I currently have a main page and a settings page. In screen manager, when i go to the settings page and change a value without clicking the save button and leave the settings page, it looks as though the settings were saved to the end user because when they return to that screen, their changes still reflect whereas they have not clicked save. How do i tackle this issue.</p>
  
  <p>I tried clearing the widgets and recreate them but i failed. Seems like Kivy runs a <code>on_pre_leave</code> event same time it runs a <code>on_pre_enter</code> event. To solve this issue it would be nice if the settings would be saved when they exit the screen OR their changes cleared when they exit the screen without clicking save. Please help:</p>
  
  <pre><code>from kivy.app import App
  from kivy.lang import Builder
  from kivy.uix.boxlayout import BoxLayout
  from kivy.uix.button import Button
  from kivy.uix.label import Label
  from kivy.uix.screenmanager import ScreenManager, Screen
  from kivy.uix.switch import Switch
  from kivy.core.window import Window
  from kivy.uix.progressbar import ProgressBar
  from kivy.clock import Clock
  
  Window.clearcolor = (252, 235, 233, 0)
  #!/usr/bin/python3
  
  class MyScreenManager(ScreenManager):
      pass
  
  
  class LoginPageScreen(Screen):
      pass
  class UserSettingsScreen(Screen):
      pass
  
  class LoginPage(BoxLayout):
      def __init__(self, **kwargs):
          super(LoginPage, self).__init__(**kwargs)
  
          self.add_widget(Label(text="[color=000000][b]Main page[/b][/color]", markup=True, size_hint_y=None, font_size='15sp'))
  
  class UserSettings(BoxLayout):
      def __init__(self, **kwargs):
          super(UserSettings, self).__init__(**kwargs)
          # self.clear_widgets()
          on_pre_enter = self.userSettingsClass()
          # on_pre_leave = self.userSettingsClass()
  
      def userSettingsClass(self):
          # self.clear_widgets()
  
          self.add_widget(Label(text="[color=000000][b]settings[/b][/color]", markup=True, font_size='15sp'))
          self.testSwitch = Switch()
          self.add_widget(self.testSwitch)
  
          self.add_widget(Button(text='Save', font_size=40, size_hint_y=None, height=80, on_press=self.updateSettings))
  
      def updateSettings(self, btn):
          print('this is how i currently save settings, if the user does not click this button and come back to this page'
                ' it looks as though they saved the settings when they really did not')
  
  
  
  root_widget = Builder.load_string('''
  #:import NoTransition kivy.uix.screenmanager.NoTransition
  #:import sys sys
  MyScreenManager:
      transition: NoTransition()
  
      LoginPageScreen:
          ActionBar:
              pos_hint: {'top':1}
          ActionBar:
              pos_hint: {'top':0.07}
              ActionView:
                  ActionPrevious:
                      with_previous: False
                  ActionOverflow:
                  ActionGroup:
                      ActionButton:
                          text: 'Settings'
                          on_release: app.root.current = 'settings'
  
      UserSettingsScreen:
          ActionBar:
              pos_hint: {'top':1}
          ActionBar:
              pos_hint: {'top':0.07}
              ActionView:
                  ActionPrevious:
                      with_previous: True
                      on_release: app.root.current = 'home'
  
  
  &lt;UserSettingsScreen&gt;:
      name: 'settings'
      # on_pre_enter: userSettingsClass()
      BoxLayout:
          size_hint_y: 0.85
          pos_hint: {'center_y': .5}
          #size_hint: (None, None)
          ScrollView:
              UserSettings
                  orientation: 'vertical'
                  padding: [50,10,50,10]
                  spacing: 10
                  # size_hint: (None, None)
                  size: (1080, 3000)
  
  &lt;LoginPageScreen&gt;:
      name: 'home'
      BoxLayout:
          LoginPage
              orientation: 'vertical'
              padding: [50,10,50,10]
              spacing: 10
              # size_hint_y: 0.9
  
  ''')
  
  class ScreenManagerApp(App):
      def build(self):
          return root_widget
  
  ScreenManagerApp().run()
  </code></pre>