Pergunta

Eu estou tentando mudar a altura de um BoxLayout aninhado dentro de outro BoxLayout.Eu tentei mais de uma dúzia de combinações de tamanho, size_hints e altura, mas nada parece funcionar.O problema é que não importa o que eu faça o BoxLayouts dentro do "ContainerBox" BoxLayout, estes BoxLayouts são sempre do mesmo tamanho.Como faço para alterar a altura de aninhados BoxLayouts?Eu quero usar a kv idioma para definir as alturas não o código python.

Python

import kivy
kivy.require('1.7.1')
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from kivy.core.window import Window
Window.clearcolor = (1, 1, 1, 1)

class ContainerBox(BoxLayout):
def __init__(self, **kwargs):
    super(ContainerBox, self).__init__(**kwargs)

class Header(BoxLayout):
def __init__(self, **kwargs):
    super(Header, self).__init__(**kwargs)

class Toolbar(BoxLayout):
def __init__(self, **kwargs):
    super(Toolbar, self).__init__(**kwargs)     

class LoginScreen(GridLayout):
    f_username = ObjectProperty(None)
    f_password = ObjectProperty(None)   
    def __init__(self, **kwargs):
        super(LoginScreen, self).__init__(**kwargs)     

class LoginApp(App):
    def build(self):
        return ContainerBox()


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

Kv arquivo

# kivy 1.7.1
<LoginScreen>:
    f_username: username
    f_password: password
    GridLayout:
        size: root.width, 200
        pos: root.pos
        row_default_height: 10
        rows: 3
        cols: 2
        padding: 20
        spacing: 10     
        Label:
            text: 'User Name:'
            color: 0.212, 0.486, 0.169, 1
            font_size: 24
        TextInput:
            id: username
        Label:
            text: 'Password:'
            color: 0.212, 0.486, 0.169, 1
            font_size: 24
        TextInput:
            id: password
            password: True
        Label:
        Button:
            text: 'Login'
            background_normal: 'white_20x20.png'
            background_color: 0.212, 0.486, 0.169, 1
            font_size: 24

<Header>:
    BoxLayout:
        orientation: 'vertical'
        height: 100
        size_hint_x: 1
        size_hint_y: None
        Label:
            text: 'Dealer App'
            color: 0.212, 0.486, 0.169, 1
            font_size: 48


<Toolbar>           
    BoxLayout:
        orientation: 'horizontal'
        height: 36
        size_hint_x: 1
        size_hint_y: None
        pos: root.pos
        spacing: 5  
        Button:
            text: 'One'
            background_normal: 'white_20x20.png'
            background_color: 0.212, 0.486, 0.169, 1
            font_size: 16
        Button:
            text: 'Two'
            background_normal: 'white_20x20.png'
            background_color: 0.212, 0.486, 0.169, 1
        Button:
            text: 'Three'
            background_normal: 'white_20x20.png'
            background_color: 0.212, 0.486, 0.169, 1
        Button:
            text: 'Four'
            background_normal: 'white_20x20.png'
            background_color: 0.212, 0.486, 0.169, 1


<ContainerBox>:
    BoxLayout:
        orientation: 'vertical'
        Header:
        Toolbar:
        LoginScreen:
Foi útil?

Solução

É devido ao seu duplo-nested layouts.Por exemplo, você tem ContainerBox, que é uma BoxLayout.Assim que você adicionar para que Header, que se estende BoxLayout mas tem um size_hint de (1, 1)!Você definir o size_hint no BoxLayout contido dentro de Header, mas que não afetam o Header em si.

Então, para corrigir isso:retirar o excesso de aninhados layouts, assim:

<LoginScreen>:
    f_username: username
    f_password: password
    size: root.width, 200
    pos: root.pos
    row_default_height: 10
    rows: 3
    cols: 2
    padding: 20
    spacing: 10     
    Label:
        text: 'User Name:'
        color: 0.212, 0.486, 0.169, 1
        font_size: 24
    TextInput:
        id: username
    Label:
        text: 'Password:'
        color: 0.212, 0.486, 0.169, 1
        font_size: 24
    TextInput:
        id: password
        password: True
    Label:
    Button:
        text: 'Login'
        background_normal: 'white_20x20.png'
        background_color: 0.212, 0.486, 0.169, 1
        font_size: 24

<Header>:
    orientation: 'vertical'
    height: 100
    size_hint_x: 1
    size_hint_y: None
    Label:
        text: 'Dealer App'
        color: 0.212, 0.486, 0.169, 1
        font_size: 48


<Toolbar>           
    orientation: 'horizontal'
    height: 36
    size_hint_x: 1
    size_hint_y: None
    pos: root.pos
    spacing: 5  
    Button:
        text: 'One'
        background_normal: 'white_20x20.png'
        background_color: 0.212, 0.486, 0.169, 1
        font_size: 16
    Button:
        text: 'Two'
        background_normal: 'white_20x20.png'
        background_color: 0.212, 0.486, 0.169, 1
    Button:
        text: 'Three'
        background_normal: 'white_20x20.png'
        background_color: 0.212, 0.486, 0.169, 1
    Button:
        text: 'Four'
        background_normal: 'white_20x20.png'
        background_color: 0.212, 0.486, 0.169, 1
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top