tamj0rd2
tamj0rd2

Reputation: 5690

Kivy Gridlayout error: have no cols or rows set, layout is not triggered

I'm trying to create a basic Kivy app that has 4 labels in a GridLayout. Here's my Python code:

from kivy.lang import Builder
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label

class MyLayout(GridLayout):

    def __init__(self, **kwargs):
        Builder.load_file("mylayout.kv")
        super(MyLayout, self).__init__(**kwargs)


class MyApp(App):

    def build(self):
        return MyLayout()


if __name__ == '__main__':
    MyApp().run()

Here is my mylayout.kv file:

<MyLayout>:
    GridLayout:
        cols: 2
        rows: 4

        Label:
            text: "Hello"
        Label:
            text: "Hello2"
        Label
            text: "Hello3"
        Label
            text: "Hello4"

When I run the program, this comes up in the logs:

[INFO              ] [Logger      ] Record log in C:\Users\tjordan\.kivy\logs\kivy_15-09-22_56.txt
[INFO              ] [Kivy        ] v1.9.0
[INFO              ] [Python      ] v2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)]
[INFO              ] [Factory     ] 173 symbols loaded
[INFO              ] [Image       ] Providers: img_tex, img_dds, img_gif, img_sdl2 (img_pil, img_ffpyplayer ignored)
[INFO              ] [Text        ] Provider: sdl2
[INFO              ] [OSC         ] using <thread> for socket
[INFO              ] [Window      ] Provider: sdl2
[INFO              ] [GL          ] GLEW initialization succeeded
[INFO              ] [GL          ] OpenGL version <3.1.0 - Build 9.17.10.4229>
[INFO              ] [GL          ] OpenGL vendor <Intel>
[INFO              ] [GL          ] OpenGL renderer <Intel(R) HD Graphics>
[INFO              ] [GL          ] OpenGL parsed version: 3, 1
[INFO              ] [GL          ] Shading version <1.40 - Intel Build 9.17.10.4229>
[INFO              ] [GL          ] Texture max size <8192>
[INFO              ] [GL          ] Texture max units <16>
[INFO              ] [Shader      ] fragment shader: <No errors.>
[INFO              ] [Shader      ] vertex shader: <No errors.>
[INFO              ] [Shader      ] program: <No errors.>
[INFO              ] [Window      ] auto add sdl2 input provider
libpng warning: iCCP: known incorrect sRGB profile
[INFO              ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO              ] [Base        ] Start application main loop
[INFO              ] [GL          ] NPOT texture support is available
[WARNING           ] <__main__.MyLayout object at 0x02D0F260> have no cols or rows set, layout is not triggered.
[INFO              ] [Base        ] Leaving application in progress...

I'm really new to Kivy so I'm just trying to get a hang of the basics. I've tried moving the Builder out of init but still got the same "have no cols or rows set, layout is not triggered" error. When the program runs it puts all of the Labels on top of eachother on the bottom left corner.

Upvotes: 3

Views: 3381

Answers (1)

inclement
inclement

Reputation: 29460

Your kv rule places a GridLayout inside a GridLayout, and only sets the rows and cols for the second one. Just remove this second level such that the cols are set for the first GridLayout (your MyLayout), and the Labels added directly to this.

Upvotes: 5

Related Questions