title: How to access ID from the Python code file of an MDBoxLayout defined inside the Screen in KV file?
body: <p>I'm making a KivyMD app with 2 screens: MainScreen and DataScreen. The question relates to the DataScreen. I've divided the DataScreen inside the KV file into DataScreenTopBar and DataScreenBody, and both these components of the DataScreen are MDBoxLayouts. I want to access the ID of the DataScreenBody because I want to populate this component with data pulled from a database from inside the python file.</p>
  <p><strong>However, when I try to access the ID of the DataScreenBody I get an empty dictionary when I try to print it</strong>. I've tried all kinds of methods but I keep getting an empty dictionary. I also tried it with Clock.schedule_once, but that too gives an empty dictionary.</p>
  <p>The code inside the Python file is given below:</p>
  <pre><code>class GameShotApp(MDApp):
      def build(self):
          self.title = &quot;Game Shot&quot;
          self.icon  = &quot;./icon/favicon.png&quot;
          return WindowManager()
  
  class MainScreen(MDScreen):
      def btnClick(self):
          print(&quot;Btn Click&quot;)
  
  class DataScreen(MDScreen):
      def __init__(self, **kwargs):
          super().__init__(**kwargs)
          print(&quot;Here A:&quot;)
          print(self.ids)
          Clock.schedule_once(self.get_id)
          
      def get_id(self, dt):
          print(&quot;\nHere B:&quot;)
          print(self.ids)
          print(self.manager.get_screen(&quot;data_screen&quot;).ids)
  
  class WindowManager(ScreenManager):
      pass
  
  GameShotApp().run()
  </code></pre>
  <p>As you can see, I've tried these two different ways, in addition to others that I've not shown in the code, of accessing the ID's but I keep getting an empty dictionary. The screenshot of the output in the console is given below. The print statements' output in the picture is highlighted in yellow. Also, when I try to access the ID directly like this:
  <strong>self.ids.data_screen</strong></p>
  <p>I get the following error: AttributeError: 'super' object has no attribute '<strong>getattr</strong>'</p>
  <p><a href="https://i.stack.imgur.com/ABWoI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ABWoI.png" alt="Print Statement Output that shows empty ID dictionary" /></a></p>
  <p>The code in the KV file is given below. I've not posted all of the kv code of the MainScreen  class because it would make the question too long, and because the question is related to the DataScreen class. Please, note that all the code related to the DataScreen class both in the .py file and the .kv files is given in this question; there's no piece of code related to the DataScreen class that I've omitted.</p>
  <pre><code>&lt;WindowManager&gt;
  
  &lt;WindowManager&gt;:
      MainScreen:
          name: &quot;main_screen&quot;
      DataScreen:
          name: &quot;data_screen&quot;
  
  &lt;MainScreen&gt;:
      canvas.before:
          Color:
              rgba: rgba(&quot;#F0F5F0&quot;) # White
          Rectangle:
              pos: self.pos
              size: self.size
      MDBoxLayout:
          orientation: &quot;vertical&quot;
          MainScreenTopBar:
          MainScreenBody:
  
  &lt;DataScreen&gt;:
      id: data_screen
      canvas.before:
          Color:
              rgba: rgba(&quot;#F0F5F0&quot;) # White
          Rectangle:
              pos: self.pos
              size: self.size
      MDBoxLayout:
          orientation: &quot;vertical&quot;
          DataScreenTopBar:
          DataScreenBody:
  
  &lt;DataScreenTopBar@MDBoxLayout&gt;:
      orientation: &quot;horizontal&quot;
      size_hint: 1, 0.125
      canvas.before:
          Color:
              rgba: rgba(&quot;#049D81&quot;) # Green 2
          Rectangle:
              pos: self.pos
              size: self.size
      AnchorLayout:
          size_hint: 0.03, 1 
          TopBarIconBtn:
              icon: &quot;./icon/prev_screen.png&quot;
              tooltip_text: &quot;Go Back&quot;
              tooltip_bg_color: rgba(&quot;#F0F5F0&quot;)
              tooltip_text_color: rgba(&quot;#049D81&quot;)
              on_press: 
                  print(&quot;Go to prev screen&quot;)
                  app.root.current = &quot;main_screen&quot;
                  app.root.transition.direction = &quot;right&quot;
      MDBoxLayout:
          size_hint: 0.51, 1 
          TopBarLabel:
              text: &quot;Game Shot&quot;
              halign: &quot;right&quot;
              color: rgba(&quot;#F0F5F0&quot;) # White
      MDBoxLayout:
          size_hint: 0.46, 1 
  
  &lt;DataScreenBody@MDBoxLayout&gt;:
      id : data_screen_body
      orientation: &quot;horizontal&quot;
      size_hint: 1, 0.875
      canvas.before:
          Color:
              rgba: rgba(&quot;#F0F5F0&quot;) # White
          Rectangle:
              pos: self.pos
              size: self.size
  </code></pre>
  <p>The components used in the KV code such as TopBarLabel &amp; TopBarIconBtn are defined in the same KV file, but before DataScreen class definition in the KV file.</p>
  <p>As you can see, I've given both the DataScreen and DataScreenBody id's but when I try to access either or both of them, I get an empty dictionary in the console when I try to print it out.</p>