Skip to content

Instantly share code, notes, and snippets.

@driscollis
Created June 4, 2019 14:16
Show Gist options
  • Save driscollis/e467de222d80bd2cc371b6d05e15a70f to your computer and use it in GitHub Desktop.
Save driscollis/e467de222d80bd2cc371b6d05e15a70f to your computer and use it in GitHub Desktop.
Kivy layout example
import kivy
import random
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
red = [1,0,0,1]
green = [0,1,0,1]
blue = [0,0,1,1]
purple = [1,0,1,1]
class HBoxLayoutExample(App):
"""
Horizontally oriented BoxLayout example class
"""
def build(self):
"""
Horizontal BoxLayout example
"""
layout = BoxLayout(padding=10)
colors = [red, green, blue, purple]
for i in range(5):
btn = Button(text="Button #%s" % (i+1),
background_color=random.choice(colors)
)
layout.add_widget(btn)
return layout
class VBoxLayoutExample(App):
"""
Vertical oriented BoxLayout example class
"""
def setOrientation(self, orient):
""""""
self.orient = orient
def build(self):
""""""
layout = BoxLayout(padding=10, orientation=self.orient)
for i in range(5):
btn = Button(text="Button #%s" % (i+1) )
layout.add_widget(btn)
return layout
if __name__ == "__main__":
app = HBoxLayoutExample()
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment