title: How can I bind a button on the .kv file to make it play a sound?
body: <p>Hello StackOverflow community,
  I would like to ask for some help as before asking I did a long research but found nothing to help me out.</p>
  
  <p>I have a school project that I decided to code with Python using Kivy for cross-platform. My project is about a SoundBox, to simplify I need to first create buttons and bind them to play various sounds. On pure python code (without a .kv file), I learned how to bind a button to make it play a sound, so I decided to reach the next level that is the Screen Management part. I kind of learned that to using now a .kv file to make it simple but I'm stuck on how to bind a button using .kv file.</p>
  
  <p>I tried out some stuff but always ended up with errors on the console, also (but it's not really important for now), my Fade Transition doesn't work.
  Your help is highly appreciated, thanks in advance.</p>
  
  <p><strong>.py:</strong></p>
  
  <pre><code>from kivy.app import App
  from kivy.uix.button import Button
  from kivy.core.audio import SoundLoader
  from kivy.uix.boxlayout import BoxLayout
  from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
  
  sound = SoundLoader.load('Sunset_Lover.ogg')
  sm = ScreenManager()
  
  class ScreenManager(ScreenManager):
      pass
  
  class Menu(Screen):
      pass
  
  class Genre(Screen):
      pass
  
  class TestApp(App):
      def build(self):
          sm.add_widget(Menu(name='menu'))
          sm.add_widget(Genre(name='genre'))
          return sm
      def son(self, instance):
          if sound:
              sound.play()
  
  if __name__ == "__main__":
      TestApp().run()
  </code></pre>
  
  <p><strong>.kv:</strong></p>
  
  <pre><code>#: import FadeTransition kivy.uix.screenmanager.FadeTransition
  
  &lt;ScreenManager&gt;:
      FadeTransition:
      Menu:
      Genre:
  &lt;Menu&gt;:
      BoxLayout:
          Button:
              text: "Commencer"
              size_hint: 1, 1
              pos_hint: {'x': 0.3, 'y':0.3}
              on_press: root.manager.current = 'genre'
  &lt;Genre&gt;:
      BoxLayout:
          Button:
              text: "Exemple1"
              size_hint: 0.2, 0.2
              pos_hint: {'x': 0.2, 'y':0.2}
              on_press: root.son()
  </code></pre>