Frage

Ich versuche, die Höhe eines Boxlayouts zu ändern, das in einem anderen BoxLayout verschachtelt ist.Ich habe mehr als ein Dutzend Kombinationen aus Größe, size_hints und Höhe ausprobiert, aber nichts scheint zu funktionieren.Das Problem ist, egal was ich mit den BoxLayouts im BoxLayout "ContainerBox" mache, diese BoxLayouts haben immer die gleiche Größe.Wie ändere ich die Höhe von verschachtelten BoxLayouts?Ich möchte die kv-Sprache verwenden, um die Höhen festzulegen, nicht den Python-Code.

Pythonschlange

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-Datei

# 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:
War es hilfreich?

Lösung

Das liegt an Ihren doppelt verschachtelten Layouts.Zum Beispiel haben Sie ContainerBox, das ist ein BoxLayout.Also fügst du das hinzu Header, die sich ausdehnt BoxLayout hat aber eine size_hint von (1, 1)!Sie stellen die size_hint auf der BoxLayout im Inneren enthalten Header, aber das hat keinen Einfluss auf die Header selbst.

Also, um das zu beheben:entfernen Sie die zusätzlichen verschachtelten Layouts wie folgt:

<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
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top