title: How to dynamically add widgets on a different screen depending on which button is pressed if the buttons were added dynamically as well?
body: <h1>The Problem</h1>
  <p>I'm attempting to create dynamic buttons tied to &quot;pages&quot; in my program. Each button and page inherits a name from a database that I have tied to the program. In this case, I'm having trouble adding widgets to a screen and changing to that screen on button press. So far, I'm able to implement dynamic buttons that could change the screen and receive variables for text but the widgets aren't being added or aren't showing up.</p>
  <h1>The Code</h1>
  <p>Upon request, I recreated the code with the same problem my program was experiencing.</p>
  <pre><code>from kivy.lang import Builder
  from kivymd.app import MDApp
  from kivy.uix.screenmanager import Screen, ScreenManager
  from kivy.properties import StringProperty
  from kivymd.uix.button import MDRectangleFlatButton
  from functools import partial
  
  kv = '''
  ScreenManager
      ScreenOne:
      ScreenTwo:
      ScreenThree:
      
  &lt;ScreenOne&gt;:
      
      ScrollView:
      
          MDGridLayout:
              id: screen_one
              cols: 1
              adaptive_height: True
              padding: &quot;40dp&quot;
              MDFlatButton:
                  text: &quot;Next Page&quot;
                  theme_text_color: &quot;Custom&quot;
                  text_color: 0, 0, 1, 1
                  pos_hint: {&quot;center_x&quot;: .5, &quot;center_y&quot;: .5}
                  on_press: root.manager.current = 'Screen 2'
          
  &lt;ScreenTwo&gt;:
      name: 'Screen 2'
      on_pre_enter: root.on_load()
      ScrollView:
      
          MDGridLayout:
              id: screen_two
              cols: 1
              adaptive_height: True
              padding: &quot;40dp&quot;
  &lt;ScreenThree&gt;:
      name: 'Screen 3'
      ScrollView:
      
          MDGridLayout:
              id: screen_three
              cols: 1
              adaptive_height: True
              padding: &quot;40dp&quot;
  '''
  sm = ScreenManager()
  
  class ScreenOne(Screen):
      pass
  
  
  
  
  class ScreenTwo(Screen):
      def on_load(self):
          name_list = ['Page 1', 'Page 2', 'Page 3']
          button_list = []
          for x in name_list:
              page_button = MDRectangleFlatButton(text = x, theme_text_color = &quot;Custom&quot;)
              button_list.append(page_button)
          for x in button_list:
              x.bind(on_press = partial(self.load_home, x.text))
              self.ids.screen_two.add_widget(x)
              
              
              
      def load_home(self, name, *largs):
          self.manager.current = 'Screen 3'
          Screen3 = ScreenThree()
          Screen3.on_load(name)
          
          
          
          
      def on_leave(self):
          self.ids.screen_two.clear_widgets()
          
          
  # Below is the particular code I'm having trouble with. It's supposed
  # to display a page with a button with the same name as the button
  # that sends you to Screen Three. However, the button is not showing up.
  class ScreenThree(Screen):
      def on_load(self, name, *kwargs):
          test_button = MDRectangleFlatButton(text = name, theme_text_color = &quot;Custom&quot;)
          self.ids.screen_three.add_widget(test_button)
  
  sm.add_widget(ScreenOne(name=&quot;Screen 1&quot;))
  sm.add_widget(ScreenTwo(name=&quot;Screen 2&quot;))
  sm.add_widget(ScreenThree(name=&quot;Screen 3&quot;))
  
  class TestApp(MDApp):
      def build(self):
          screen = Builder.load_string(kv)
          return screen
  
  
  TestApp().run()
  
  </code></pre>
  <p>All help, tips, and solutions would be greatly appreciated. Thank you in advanced.</p>