title: Add function to kivy screen
body: <p>When I leave the mainscreen for the first time, the screen is duplicated. When I return to mainscreen for the first time, the screen is all black. But then it works fine.</p>
  <p>The image of the second screen the first time I swipe <a href="https://i.stack.imgur.com/J6IGL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/J6IGL.png" alt="enter image description here" /></a>.
  The mainscreen image the first time I come back: <a href="https://i.stack.imgur.com/1nST2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1nST2.png" alt="enter image description here" /></a>. But then it works fine for the second and other swipe.</p>
  <pre><code>Builder.load_string(&quot;&quot;&quot;
  &lt;MenuScreen&gt;:
      BoxLayout:
          Button:
              text: 'Go to main screen'
              on_press: root.manager.current = 'main'
              size_hint: None, None
              size: self.texture_size
          Button:
              text: 'Go to second screen'
              on_press: root.manager.current = 'second'
              size_hint: None, None
              size: self.texture_size
  &lt;MainScreen&gt;:
      # add Game widget
      Game:
          power: powerbar
          lifes: lifesbar
          id: game
      BoxLayout:
          Button:
              text: 'Go to the menu screen'
              on_press: root.manager.current = 'menu'
              size_hint: None, None
              size: self.texture_size
      FloatLayout:
          ShootProgressBar:
              id: powerbar
              pos_hint: {'x': 0.035, 'y': 0.9}
              size_hint: (0.25, 0.1)
              max:10
          LifesProgressBar:
              canvas:
                  Color:
                      rgba: 1, 0, 0, 1
              id: lifesbar
              pos_hint: {'x': 0.7, 'y': 0.92}
              size_hint: (0.25, 0.1)
              max:3
              value:3
          Image:
              id: ethereum
              size_hint: (0.04, 0.04)
              pos_hint: {'x': 0.002, 'y': 0.93}
              allow_stretch: True
              source: &quot;ethereum.png&quot;
          Image:
              id: lifes_img
              size_hint: (0.04, 0.04)
              pos_hint: {'x': 0.952, 'y': 0.93}
              allow_stretch: True
              source: &quot;lifes.png&quot;
  
  &lt;SecondScreen&gt;:
      # add Game widget
      Game:
          power: powerbar
          lifes: lifesbar
          id: game
      BoxLayout:
          Button:
              text: 'Back to menu'
              on_press: root.manager.current = 'menu'
              size_hint: None, None
              size: self.texture_size
      FloatLayout:
          ShootProgressBar:
              id: powerbar
              pos_hint: {'x': 0.035, 'y': 0.9}
              size_hint: (0.25, 0.1)
              max:10
          LifesProgressBar:
              canvas:
                  Color:
                      rgba: 1, 0, 0, 1
              id: lifesbar
              pos_hint: {'x': 0.7, 'y': 0.92}
              size_hint: (0.25, 0.1)
              max:3
              value:3
          Image:
              id: ethereum
              size_hint: (0.04, 0.04)
              pos_hint: {'x': 0.002, 'y': 0.93}
              allow_stretch: True
              source: &quot;ethereum.png&quot;
          Image:
              id: lifes_img
              size_hint: (0.04, 0.04)
              pos_hint: {'x': 0.952, 'y': 0.93}
              allow_stretch: True
              source: &quot;lifes.png&quot;
              
  &lt;-ShootProgressBar@ProgressBar&gt;:
      canvas:
          Color:
              rgb: 1, 1, 1
          BorderImage:
              border: (12, 12, 12, 12)
              pos: self.x, self.center_y - 3
              size: self.width, 24
              source : 'black_bg.png'
          BorderImage:
              border: [int(min(self.width * (self.value / float(self.max)) if self.max else 0, 12))] * 4
              pos: self.x, self.center_y - 12
              size: self.width * (self.value / float(self.max)) if self.max else 0, 24
              source : 'blue_fg.png'
              
  &lt;-LifesProgressBar@ProgressBar&gt;:
      canvas:
          Color:
              rgb: 1, 1, 1
          BorderImage:
              border: (12, 12, 12, 12)
              pos: self.x, self.center_y - 14
              size: self.width, 24
              source: 'black_bg.png'
          BorderImage:
              border: [int(min(self.width * (self.value / float(self.max)) if self.max else 0, 12))] * 4
              pos: self.x, self.center_y - 12
              size: self.width * (self.value / float(self.max)) if self.max else 0, 24
              source: 'green2_fg.png'
  
  &lt;ColourScreen&gt;:
      BoxLayout:
          orientation: 'vertical'
          Label:
              text: 'colour {:.2},{:.2},{:.2} screen'.format(*root.colour[:3])
              font_size: 30
          Widget:
              canvas:
                  Color:
                      rgba: root.colour
                  Ellipse:
                      pos: self.pos
                      size: self.size
          BoxLayout:
              Button:
                  text: 'goto first screen'
                  font_size: 30
                  on_release: app.root.current = 'first'
              Button:
                  text: 'get random colour screen'
                  font_size: 30
                  on_release: app.root.new_colour_screen()
  &quot;&quot;&quot;)
  
  
  # Declare both screens
  
  class MenuScreen(Screen):
      pass
  
  
  class MainScreen(Screen):
      def on_enter(self, *args):
          self.ids.game.initialize()
          self.ids.game.power.value = 0
          self.ids.game.lifes.value = 3
          self.update_event = Clock.schedule_interval(self.ids.game.update_glsl, 1.0 / 60.0)
  
      def on_leave(self, *args):
          self.update_event.cancel()
          self.ids.game.indices = []
          self.ids.game.vertices = []
          self.ids.game.particles = []
          self.ids.game.canvas.clear()
          self.update_event = None
              
  
  
  class SecondScreen(Screen):
  
      def on_enter(self, *args):
          self.ids.game.initialize()
          self.ids.game.power.value = 0
          self.ids.game.lifes.value = 3
          self.update_event = Clock.schedule_interval(self.ids.game.update_glsl, 1.0 / 60.0)
  
      def on_leave(self, *args):
          self.update_event.cancel()
          self.ids.game.indices = []
          self.ids.game.vertices = []
          self.ids.game.particles = []
          self.ids.game.canvas.clear()
          self.update_event = None
  </code></pre>
  <p>What I want is to use conditions to change the screen. For example, <code>if self.parent.power.value == 10: sm.current = 'second'</code></p>