Kivy Gridlayout错误:未设置列数或行,未触发布局 [英] Kivy Gridlayout error: have no cols or rows set, layout is not triggered

查看:81
本文介绍了Kivy Gridlayout错误:未设置列数或行,未触发布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个基本的Kivy应用程序,该应用程序在GridLayout中具有4个标签.这是我的Python代码:

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()

这是我的mylayout.kv文件:

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...

我真的是Kivy的新手,所以我只是想了解一些基础知识.我尝试将Builder移出 init ,但仍然出现相同的未设置列数或行数,未触发布局"的错误.程序运行时,将所有标签彼此放在左下角.

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.

推荐答案

您的kv规则将GridLayout放置在GridLayout中,并且只为第二个设置行和列.只需删除此第二级,以便为第一个GridLayout(您的MyLayout)设置cols,然后将Labels直接添加到此.

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.

这篇关于Kivy Gridlayout错误:未设置列数或行,未触发布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆