在一个网格布局中设置随机列号
Random column number set in one gridlayout
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()
(
如何在同一行中设置男、女 GridLayout.If 我使用两个 gridlaout 第一组 cols: 4 和第二组 cols: 2 并在弹出窗口中显示然后它给出错误 "Popup can have only one widget as content" .那么如何在一个 GridLayout 中设置第一行 4 列和第二行 2 列。
光靠 gridlayout 是做不到的。
您可以制作一个两列的网格布局,然后在需要拆分的网格中放置水平框布局。
或者您可以使用堆栈布局。 stacklayout
我只会在垂直框布局中使用两个网格布局。
您只需将两个网格布局放在一个框布局中。所以 Popup 将包含 boxlayout,并且不会抱怨多个小部件。
MyBoxLayout:
orientation: "vertical"
GridLayout1:
cols: 2
GridLayout2:
cols: 4
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()
如何在同一行中设置男、女 GridLayout.If 我使用两个 gridlaout 第一组 cols: 4 和第二组 cols: 2 并在弹出窗口中显示然后它给出错误 "Popup can have only one widget as content" .那么如何在一个 GridLayout 中设置第一行 4 列和第二行 2 列。
光靠 gridlayout 是做不到的。
您可以制作一个两列的网格布局,然后在需要拆分的网格中放置水平框布局。
或者您可以使用堆栈布局。 stacklayout
我只会在垂直框布局中使用两个网格布局。
您只需将两个网格布局放在一个框布局中。所以 Popup 将包含 boxlayout,并且不会抱怨多个小部件。
MyBoxLayout:
orientation: "vertical"
GridLayout1:
cols: 2
GridLayout2:
cols: 4