我正在尝试创建一个带有画布的Box布局,看起来像这样:
<MyScreenManager>:
IntroScreen:
<IntroScreen>:
name: 'introscreen'
BoxLayout:
orientation:'horizontal'
BoxLayout:
canvas:
Color:
rgb: 1, 0, 0
Rectangle:
size: self.size
spacing: 10
TextInput:
id: login
text: "Login"
multiline: False
size_hint_y: 0.5
size_hint_x: 0.4
height: 10
#padding_top: 10
font_size: 10
Button:
text: "Connect"
on_release: root.current = 'mainpage'
您能否建议如何修改我的kivin语言,使其看起来像第一个窗口?
答案 0 :(得分:1)
下面的代码怎么样?这是使用AnchorLayout
来对齐BoxLayout
的中心和内部到垂直中心。它还使用一些绑定来确定文本字段的高度和按钮的宽度。
<MyScreenManager>:
IntroScreen:
<IntroScreen@Screen>:
name: 'introscreen'
AnchorLayout:
anchor_x: 'center'
anchor_y: 'center'
BoxLayout:
orientation:'horizontal'
size_hint: .5, .1
canvas:
Color:
rgb: 1, 0, 0
Rectangle:
pos: self.pos
size: self.size
spacing: 10
pos_hint: {'center_x':.5, 'center_y': .5}
AnchorLayout:
anchor_x: 'left'
size_hint_x: 1
TextInput:
id: login
text: "Login"
multiline: False
height: self.minimum_height
size_hint_y: None
font_size: 10
AnchorLayout:
anchor_x: 'right'
size_hint_x: None
Button:
size_hint: None, None
height: 20
width: self.texture_size[0]
padding: 10, 10
text: "Connect"
on_release: root.current = 'mainpage'