title: Why isn't this rectangle centered in Kivy?
body: <p>I'm trying to draw a rectangle in the center of my widget:</p>
  
  <pre><code>from kivy.app import App
  from kivy.uix.widget import Widget
  from kivy.graphics import Rectangle
  
  
  class MyWidget(Widget):
      def __init__(self):
          super(MyWidget, self).__init__()
          with self.canvas:
              Rectangle(pos=(self.center_x, self.center_y)
  
  
  class MyApp(App):
      def build(self):
          return MyWidget()
  
  
  if __name__ == '__main__':
      MyApp().run()
  </code></pre>
  
  <p>This is what I'm getting:</p>
  
  <p><a href="https://i.stack.imgur.com/LwzU0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LwzU0.png" alt="Image indeed"></a></p>
  
  <p>Doing the exact same thing using a <code>.kv</code> file works:</p>
  
  <pre><code>&lt;MyWidget&gt;:
      canvas:
          Rectangle:
              pos: self.center_x, self.center_y
  </code></pre>
  
  <p>Please explain how to achieve what I'm trying to do, and why it does work using a <code>.kv</code> file, as opposed to Python code. Thank you</p>