ShibaYuuta
ShibaYuuta

Reputation: 27

How to "anchor" an BoxLayout on top side inside an TabedPannel with Kivy?

I have a BoxLayout inside TabbedPannel with a "height size fixed" and i want it to "anchor" at the top, so when i re-size the height of the GUI it follows the top part and open space at the bottom.

I tried a many ways to do it, like pos_hint, AnchorLayout, putting a widget at the bottom of everything, but i hasnt able to make it work.

enter image description here

So here is the code.

Exemple.py

from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty


class TabMain(Widget):
    def __init__(self, *args):
        super(TabMain, self).__init__(*args)
        self.ids["panel"]._tab_layout.padding = '-2dp', '-2dp', '-2dp', '-2dp'

class GuiApp(App):
    def build(self):
        return TabMain()


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

gui.kv

<TabMain>
    TabbedPanel:
        id: panel
        size: root.width, root.height
        do_default_tab: False
        tab_pos: 'bottom_mid'
        tab_width: self.size[0] / 1
        canvas:
            Rectangle:
                size: self.size

        TabbedPanelItem:
            text: "Robos"
            background_color: (48/255, 48/255, 48/255, 1) if self.state == 'down' else (88/255, 88/255, 88/255, 1)
            background_down: ""
            background_normal: ""
            TabbedPanel:
                do_default_tab: False
                tab_width: 115

                TabbedPanelItem:
                    text: "Solicitar"
                    TabbedPanel:
                        tab_pos: 'bottom_right'
                        do_default_tab: False
                        TabbedPanelItem:

                            text: "Solicitar"
                            AnchorLayout:
                                anchor_y: 'top'
                                BoxLayout:

                                    orientation: "vertical"
                                    spacing: 4
                                    padding: 4
                                    pos_hint: {'y': 1}

                                    BoxLayout:
                                        size_hint: 1, None
                                        height: 30

                                        Label:
                                            text: "Login"
                                            halign: "right"
                                        TextInput:
                                            multiline: False
                                            size_hint: 1.7 , 1
                                        Label:
                                            text: "Senha"
                                        TextInput:
                                            multiline: False
                                            size_hint: 1.7, 1
                                    BoxLayout:
                                        size_hint: 1, None
                                        height: 30
                                        Label:
                                            text: "Data Inicial"
                                        TextInput:
                                            multiline: False
                                            size_hint: 1.7, 1
                                        Label:
                                            text: "Data Final"
                                        TextInput:
                                            multiline: False
                                            size_hint: 1.7, 1
                                    BoxLayout:
                                        size_hint: 1, None
                                        height: 45
                                        Label:
                                            text: "Lembrar informações dadas pelo usuario"
                                            size_hint: None, 1
                                            width: 350
                                        CheckBox:
                                            size_hint: 0.3, 1
                                        Label:
                                            size_hint: 1.4, 1
                                        Button:
                                            text: "Iniciar"
                                            size_hint: 2, 0.90
                                    BoxLayout:
                                        size_hint: 1, None
                                        height:60
                                        orientation: "vertical"
                                        spacing: 0
                                        BoxLayout:
                                            size_hint: 1, None
                                            height: 30
                                            ProgressBar:
                                                value: 25
                                            Label:
                                                size_hint: 0.1, 1
                                                text: "25.0%"
                                        BoxLayout:
                                            valign: "top"
                                            size_hint: 1, None
                                            height: 30
                                            Label:
                                                size_hint: None, None
                                                text: "Alguma informação"
                                                size: self.texture_size
                                            Label:
                                            Label:
                                                size_hint: None, None
                                                text: "Parado"
                                                size: self.texture_size
                                            Label:
                                                size_hint: 0.1, 1
                                    BoxLayout:
                                        size_hint: 1, None
                                        height: 15


                        TabbedPanelItem:
                            text: "Relatorio"
                            Label:
                                text: "Banco de Dados"

Upvotes: 0

Views: 682

Answers (1)

John Anderson
John Anderson

Reputation: 38992

The BoxLayout tries to use all the space it has been given, so it ends up with empty space that shows up at the top of the BoxLayout. To fix that, you can use minimum_height:

                        AnchorLayout:
                            anchor_y: 'top'
                            BoxLayout:

                                orientation: "vertical"
                                spacing: 4
                                padding: 4
                                pos_hint: {'y': 1}
                                size_hint: 1, None
                                height: self.minimum_height

Upvotes: 1

Related Questions