title: Python Kivy Float Layout
body: <p>I have very little experience with Python and Kivy. I am helping my little nephew with his quest to build a game using the two. We are stuck at something that seems simple.</p>
  
  <p>Consider following code:</p>
  
  <pre><code>from kivy.app import App
  from kivy.uix.widget import Widget
  from kivy.properties import NumericProperty, ReferenceListProperty,\
      ObjectProperty
  from kivy.vector import Vector
  from kivy.clock import Clock
  from random import randint
  from kivy.graphics import Color, Ellipse, Rectangle
  from kivy.uix.floatlayout import FloatLayout
  import math
  
  class Fly(Widget):
      pass
  
  class Stick(Widget):
      pass
  
  class FlyBox(Widget):
      pass
  
  class GameArea(FloatLayout):
      pass
  
  class FlyApp(App):
      def build(self):
          gameArea = GameArea()
          flyBox = FlyBox()
          flyBox.canvas.add(Rectangle(pos_hint={'x': 0, 'y': .3}, size_hint=(1, .3)))
          flyBox.canvas.add(Color(1, 0, 0))
          gameArea.add_widget(flyBox)
          return gameArea
  
  
  if __name__ == '__main__':
      FlyApp().run()
  </code></pre>
  
  <p>it produces following output:</p>
  
  <p><a href="https://i.stack.imgur.com/1x8QT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1x8QT.png" alt="enter image description here"></a></p>
  
  <p>What we were trying to achieve was: </p>
  
  <ul>
  <li>The FlyBox's height should be 1/3rd the height of the GameArea's height.</li>
  <li>The FlyBox's width should be same as GameArea's width.</li>
  <li>The FlyBox's x coordinate should be 0 and its y coordinate should be 1/3rd the height of GameArea.</li>
  </ul>
  
  <p>i.e. if the game area were to be divided into 3 equal sized horizontal bands, the FlyBox should be the middle band. And as the size of game area changes (due to resizing of window), the FlyBox's size and position should change relatively.</p>
  
  <p>We are trying to avoid using a .kv file and instead do everything in Python.</p>