2017-11-21 28 views
1

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に設定同じグリッドレイアウト内の1つの行に男性、女性を設定する方法

 ランダム列番号は、一つのGridLayout

<[email protected]>: 
    text_size: self.size 
    valign: "middle" 
    padding_x: 5 

<[email protected]>: 
    multiline: False 

<[email protected]>: 
    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

。私は2つのgridlaout最初のセットcolsを使用する場合:4と2番目のセットcols:2とポップアップで表示すると、 "ポップアップはコンテンツとして1つだけのウィジェットを持つことができます"。 1つ目のGridLayoutには4列と2行2列の列があります。

答えて

1

あなたは単独でgridlayoutで行うことはできません。

2つの列を持つグリッドレイアウトを作成し、分割するグリッドに水平のボックスレイアウトを配置できます。

また、stacklayoutを使用することもできます。 stacklayout

私はちょうど縦のボックスレイアウト内に2つのグリッドレイアウトを使用します。

単純に、両方のグリッドレイアウトをボックスレイアウトに配置します。したがって、ポップアップにはboxlayoutが含まれ、複数のウィジェットについては不平を言うことはありません。

MyBoxLayout: 
    orientation: "vertical" 

    GridLayout1: 
     cols: 2 
    GridLayout2: 
     cols: 4