title: KIVY: adding buttons in a sub layout when a button is pressed (on_release)
body: <p>The screen has multiple layouts all child of a box layout. I am trying to add a button in the last sub layout (grid-layout) when a button in other layout is clicked. The code does not crash but nothing happens too. I want to add buttons to the layout with id drinkslayout when a button is clicked eg pepsi,sprite</p>
  
  <p>Python:</p>
  
  <pre><code>class MainScreen(Screen):
      pass
  
  class AnotherScreen(Screen):
      pass
  
  class ScreenManagement(ScreenManager):
      pass
  class Stacks(StackLayout):
      pass
  
  
  present=Builder.load_file('hellokivy2.kv')  #Specifying location of kv file     
  
  class MainApp(App):
  
      def build(self):
          return present
      def drinksSelect(self,value): #creating a button by referring the id of the layout in which to create button
          print(value)
          yolo = AnotherScreen()
          yolo2 = yolo.ids.newButtonLayout
          button = Button(text="value",size_hint= (0.2,0.4))
          yolo2.add_widget(button)
  
  
  if __name__ == "__main__":
      MainApp().run()
  </code></pre>
  
  <p><strong>KV</strong></p>
  
  <pre><code>#: import FadeTransition kivy.uix.screenmanager.FadeTransition
  
  ScreenManagement:
      transition: FadeTransition()
      MainScreen:
      AnotherScreen:
  
  &lt;MainScreen&gt;:
  name: "main"
  
  canvas.before:
      Color:
          rgba: 1, 1, 1, 1
      Rectangle:
          pos: self.pos
          size: self.size
  
  BoxLayout:
  
      orientation: 'vertical'
      size:root.size
  
      Button:
          text: "Slideshow"
  
      GridLayout:
  
          cols: 2
  
          Button:
              text: "Burger"
  
  
          Button:
              text: "Drinks"
              on_release: app.root.current = "other"
  
          Button:
              text: "Fries"
  
          Button:
              text: "Others"
      Label:
          text: "Your Cart"
          font_size: 40
          color:(0,0,0,1)
          size_hint_y: None
          canvas.before:
              Color:
                  rgba:150,10,200,0.5
              Rectangle:
                  pos: self.pos
                  size: self.size
  &lt;AnotherScreen&gt;:
      name: "other"
      canvas.before:
          Color:
              rgba: 1, 1, 1, 1
          Rectangle:
              pos: self.pos
              size: self.size
  
  BoxLayout:
      size:root.size
      orientation: 'vertical'
      GridLayout:
          size_hint_y:0.1
          orientation: 'vertical'
          rows: 1
          Button:
              color: 1,1,1,1
              font_size: 25
              size_hint_y:0.1
              text: "Back Home"
              on_release: app.root.current = "main"
          Label:
              text: "Project BAM"
              canvas.before:
                  Color:
                      rgba: 0,0,0,1
                  Rectangle:
                      pos: self.pos
                      size: self.size
          Button:
              color: 1,1,1,1
              font_size: 25
              size_hint_y:0.1
              text: "Profile"
              on_release: app.root.current = "main"
      Button:
          color: 1,1,1,1
          font_size: 25
          size_hint_y:0.9
          text: "Whats New"
          on_release: app.root.current = "main"
  
      GridLayout:
          rows: 2
          Button:
              text: "Pepsi"
              on_release: app.drinksSelect(1)
  
          Button:
              text: "7up"
              on_release: app.drinksSelect(2)
          Button:
              text: "Fanta"
              on_release: app.drinksSelect(3)
          Button:
              text: "Mountain Dew"
              on_release: app.drinksSelect(4)
          Button:
              text: "Diet Pepsi"
              on_release: app.drinksSelect(5)
          Button:
              text: "Sprite"
              on_release: app.drinksSelect(6)
  
      GridLayout:
          id: drinksLayout
          size_hint_y: 0.3
          orientation: 'horizontal'
          rows: 1
  
          Button:
              id: label1
              size_hint: 0.2,0.4
              background_normal:'1.jpg'
              text: 'B1'
          Button:
              id: label2
              size_hint: 0.2,0.4
              background_normal:'1.jpg'
              text: 'B1'
          Button:
              id: label3
              size_hint: 0.2,0.4
              background_normal:'1.jpg'
              text: 'B1'
  </code></pre>