Skip to content

Instantly share code, notes, and snippets.

@BoonsNaibot
Last active December 22, 2015 23:29
Show Gist options
  • Save BoonsNaibot/6546922 to your computer and use it in GitHub Desktop.
Save BoonsNaibot/6546922 to your computer and use it in GitHub Desktop.
BoxLayout inside of a RelativeLayout inside of a GridLayout positioning (updated with Button Functionality).
from kivy.uix.modalview import ModalView
from kivy.uix.gridlayout import GridLayout
from kivy.uix.relativelayout import RelativeLayout
from kivy.properties import StringProperty
from kivy.uix.behaviors import ButtonBehavior
from kivy.lang import Builder
from kivy.app import App
class ExampleGridLayout(GridLayout):
pass
class ExampleButton(ButtonBehavior, RelativeLayout):
text = StringProperty("When you click me, i don't respond.")
class MainView(RelativeLayout):
def __init__(self, **kwargs):
self.size_hint = (.5, .3)
self.pos_hint = {'center_x': .5, 'center_y': .5}
super(MainView, self).__init__(**kwargs)
button_container = ExampleGridLayout()
self.add_widget(button_container)
class TestApp(App):
def build(self):
root = MainView()
return root
Builder.load_string("""
<ExampleButton>:
state_image: 'atlas://data/images/defaulttheme/button'
canvas:
Color:
rgb: 1, 1, 1
Rectangle:
size: self.size
BorderImage:
source: self.state_image
size: self.size
BoxLayout
orientation: 'horizontal'
#center_y: root.center_y
pos_hint: {'center_x': .5, 'center_y': .5}
size_hint: .75, .75
Label:
text: root.text
shorten: True
<ExampleGridLayout>:
cols: 1
size_hint_y: None
ExampleButton:
ExampleButton:
""")
if __name__ == '__main__':
TestApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment