在一个gridlayout中设置随机列号

时间:2017-11-21 09:04:45

标签: python python-2.7 kivy kivy-language

test.py

import sqlite3 as lite

from kivy.uix.screenmanager import Screen
from kivy.app import App
from kivy.lang import Builder
from kivy.core.window import Window

Window.size = (600, 325)

class UserGroup(Screen):
    pass


class FactUserGroup(App):

    def build(self):
        self.root = Builder.load_file('test.kv')
        return self.root


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

test.kv

<CustomLabel@Label>:
    text_size: self.size
    valign: "middle"
    padding_x: 5

<SingleLineTextInput@TextInput>:
    multiline: False

<GreenButton@Button>:
    background_color: 1, 1, 1, 1
    size_hint_y: None
    height: self.parent.height * 0.120

UserGroup

    GridLayout:
        cols: 2
        padding : 30,30
        spacing: 20, 20
        row_default_height: '30dp'

        Label:
            text: 'Male'
            text_size: self.size
            valign: 'middle'

        CheckBox:
            group: 'check'
            id : chk


        Label:
            text: 'Female'
            text_size: self.size
            valign: 'middle'

        CheckBox:
            group: 'check'

        CustomLabel:
            text: 'age'
            text_size: self.size
            valign: 'middle'

        SingleLineTextInput:
            id: age


        GreenButton:
            text: 'Ok'


        GreenButton:
            text: 'Cancel'
            on_press: app.stop()

enter image description here

如何在同一个GridLayout中设置一行中的男性,女性。如果我使用两个gridlaout第一组cols:4和第二组cols:2并弹出显示然后它给出错误“Popup只能有一个小部件作为内容“。那么如何设置一个GridLayout,第一行有4个cols,第二行有2个cols。

1 个答案:

答案 0 :(得分:1)

单独使用gridlayout无法做到这一点。

您可以创建一个包含两列的gridlayout,并将水平boxlayout放入您需要拆分的网格中。

或者您可以使用stacklayout。 stacklayout

我只想在垂直boxlayout中使用两个gridlayout。

您只需将两个网格布局放在一个boxlayout中。因此Popup将包含boxlayout,并且不会抱怨多个小部件。

MyBoxLayout:
    orientation: "vertical"

    GridLayout1:
        cols: 2
    GridLayout2:
        cols: 4
相关问题