Skip to content

Instantly share code, notes, and snippets.

@kived
Last active August 29, 2015 14:15
Show Gist options
  • Save kived/c5c994a84efb62eebf56 to your computer and use it in GitHub Desktop.
Save kived/c5c994a84efb62eebf56 to your computer and use it in GitHub Desktop.
Kivy: centered grid
import kivy
kivy.require('1.8.1')
from kivy.app import App
from kivy.lang import Builder
root = Builder.load_string('''
BoxLayout:
orientation: 'vertical'
Label:
size_hint_y: None
height: dp(50)
text: 'Label'
AnchorLayout:
id: anchor_layout
Button:
size_hint_y: None
height: dp(50)
text: 'Button'
on_press: app.add_grid()
''')
class TestApp(App):
def build(self):
return root
def add_grid(self):
grid = GridLayout()
# ... set up grid layout here
root.ids.anchor_layout.add_widget(grid)
if __name__ == '__main__':
TestApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment