Grid Layout and Stack Layout in Kivy does not work for me

0

It does nothing that I started to learn Kivy, I'm in the different types of Layout but I do not work either the Grid Layout or the Stack Layout. I do not miss any mistakes; the problem is that when I run the program it stays in total black. Help please.

GridLayout.py

import kivy
kivy.require('1.9.0')

from kivy.app import App
from kivy.uix.gridlayout import GridLayout

class GridLayoutApp(App):

def build(self):
    return GridLayout()

GridLayoutApp().run()

Grid.kv

<GridLayout>:
cols: 2
rows: 2
padding: 10
spacing: 10

Button:
    text: '1st'
    size_hint_x: None
    width: 200

Button:
    text: '2nd'

Button:
    text: '3rd'
    size_hint_x: None
    width: 200

Button:
    text: '4th'

StackLayout.py

import kivy
kivy.require('1.9.0')

from kivy.app import App
from kivy.uix.stacklayout import StackLayout

class StackLayoutApp(App):

    def build(self):
        return StackLayout()
StackLayoutApp().run()

Stack.kv

<GridLayout>:
cols: 2
rows: 2
padding: 10
spacing: 10

Button:
    text: '1st'
    size_hint_x: None
    width: 200

Button:
    text: '2nd'

Button:
    text: '3rd'
    size_hint_x: None
    width: 200

Button:
    text: '4th'

    
asked by Chris 15.11.2018 в 01:21
source

1 answer

0

I'm new to kivy, but I think the layouts are transparent, you need to draw a rectangle in the layout so that the buttons can be seen.

  #:kivy 1.9.0
<GridLayout>:
    cols: 2
    rows: 2
    padding: 10
    spacing: 10
    canvas: #Canvas nos permite dibujar sobre el layout
        Color:
            rgb: 1,1,1 #Cada uno significa 100%, rgb trabaja con porcentajes
        Rectangle:
            #Le damos al rectangle el tamaño del layout para que ocupe toda la pantalla.
            size: self.size
            pos: self.pos

    Button:
        text: '1st'
        size_hint_x: None
        width: 200

    Button:
        text: '2nd'

    Button:
        text: '3rd'
        size_hint_x: None
        width: 200

    Button:
        text: '4th'

I'm new to this programming and new to the forum, I hope I've made myself understood.

    
answered by 10.01.2019 в 08:05