erknrio
3/6/2017 - 1:38 PM

Nesting Grid Layouts in Kivy

Nesting Grid Layouts in Kivy

#!/usr/bin/env python3
# App to magane a bot with a webcam
# Py modules
import requests
# Kivy imports
import kivy
kivy.require('1.9.1') # replace with your current kivy version !
# Kivy modules
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
import kivy.uix.gridlayout as gridl

class VideoGrid(gridl.GridLayout):
    pass
class ButtonsGrid(gridl.GridLayout):
    apiURL = 'https://api.github.com/'
    def forward(self, btn):
        print(btn.text)
        # r = requests.get(self.apiURL + "events")
        # response = r.json()
        # print(response)
    def right(self, btn):
        print(btn.text)
        # r = requests.get(self.apiURL + "events")
        # response = r.json()
        # print(response)
    def back(self, btn):
        print(btn.text)
        # r = requests.get(self.apiURL + "events")
        # response = r.json()
        # print(response)
    def left(self, btn):
        print(btn.text)
        # r = requests.get(self.apiURL + "events")
        # response = r.json()
        # print(response)

class ContainerBox(BoxLayout):
    pass

class ButtonsGridApp(App):
    def build(self):
        return ContainerBox()

if __name__ == '__main__':
    ButtonsGridApp().run()
# buttonsgrid.kv
<VideoGrid>
    cols: 1
    rows: 1
    Button:
        text: 'Video'
<ButtonsGrid>:
    cols: 3
    rows: 5
    Button:
        id: btn00
        text: '0,0'
        disabled: True
    Button:
        id:btnUp
        text: 'Adelante'
        on_press: root.forward(btnUp)
    Button:
        id: btn02
        text: '0,2'
        disabled: True
    Button:
        id:btnLeft
        text: 'Izquierda'
        on_press: root.left(btnLeft)
    Button:
        id: btn11
        text: '1,1'
        disabled: True
    Button:
        id:btnRight
        text: 'Derecha'
        on_press: root.right(btnRight)
    Button:
        id: btn20
        text: '2,0'
        disabled: True
    Button:
        id:btnDown
        text: 'Atrás'
        on_press: root.back(btnDown)
    Button:
        id: btn22
        text: '2,2'
        disabled: True
<Status>:
    cols: 1
    rows: 1


<ContainerBox>:
    orientation: 'horizontal'
    VideoGrid:
    ButtonsGrid