Created
June 4, 2019 14:16
-
-
Save driscollis/e467de222d80bd2cc371b6d05e15a70f to your computer and use it in GitHub Desktop.
Kivy layout example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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