Kivy label left align and sizing

Viewed 10963

I have been running against this wall now for almost a day. I feel like I have tried everything. First here is what I want and what I have visually.

This what I have right now:

enter image description here

What I want is this:

enter image description here

In the images 'CurrentHistory:\nHeader:' is a single label. I can get it align left but I can't get it not have massive padding top and bottom. I's like the label is square and not a rectangle just around the text. I have been Kivy'ing now for about 2 days so please forgive me if I missed something super basic.

EDIT

I updated with a fully functional demo. The odd thing is that the .kv produced label does exactly what I want it to do, but the Label produced via python does not.

The SegmentLayout is identical to the GridLayout defined in the .kv file :(

The overall layout is this: .kv

#:kivy 1.8.0

<MainWidget>
    BoxLayout
        size: root.size

        ScrollView
            id: scrlv
            size_hint: .75, 1

            GridLayout
                cols: 1
                size_hint: 1, None
                height: max(self.minimum_height, scrlv.height)

                canvas:
                    Color:
                        rgba: 150/255, 150/255, 150/255, 1
                    Rectangle:
                        pos: self.pos
                        size: self.size

                SegmentLayout

                GridLayout
                    cols: 1
                    size_hint: 1,None
                    height: self.minimum_height

                    Label
                        text: '[b]CurrentHistory:[/b]\nHeader:'
                        size_hint: (None, None)
                        halign: 'left'
                        markup: True
                        size: self.texture_size

                    TextInput
                        size_hint: (1,None)
                        height: self.minimum_height
                        text: 'Enter Text Here'

        BoxLayout
            orientation: "vertical"
            size_hint: .25, 1

            canvas:
                Color:
                    rgba: 240/255, 180/255, 80/255, 1
                Rectangle:
                    pos: self.pos
                    size: self.size

            Label
                text: "Label 1"
            Label
                text: "Label 2"

python driver demo

import kivy

kivy.require('1.8.0') # replace with your current kivy version !

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.factory import Factory

from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput

class SegmentLayout(GridLayout):

    def __init__(self, **kwargs):
        super(SegmentLayout, self).__init__(cols=1, size_hint=(1,None), **kwargs)
        self.bind(minimum_height=self.setter('height'))

        label_text = '[b]CurrentHistory:[/b]\nHeader:'

        label = Label(text=label_text, halign='left', size_hint=(None,None), markup=True)
        label.bind(size=label.setter('texture_size'))    
        self.add_widget(label)

        text_input = TextInput(text='Enter Text Here', size_hint=(1,None))
        text_input.bind(minimum_height=text_input.setter('height'))
        self.add_widget(text_input)

class MainWidget(Widget):
    pass

class MyApp(App):

    def build(self):
        return MainWidget()

Factory.register('SegmentLayout', cls=SegmentLayout)

if __name__ == '__main__':
    MyApp().run()
1 Answers
Related