python – Kivy label left align and sizing

بدون دیدگاه


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.

The overall layout is this: .kv

<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


        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"

SegmentLayout.py

class SegmentLayout(GridLayout):

    def __init__(self, **kwargs):
        kwargs['cols'] = 1
        kwargs['size_hint'] = (1,None)
        super(SegmentLayout, self).__init__(**kwargs)
        self.__segment = kwargs.get('segment', Segment(0,0,"Header:nEnter Text Here",8))
        self.bind(minimum_height=self.setter('height'))

        header = self.__segment.get_header()
        s_type = self.__segment.segment_type
        if header != '':
            label_text = '[b]{}:[/b]n{}'.format(
                escape_markup(s_type),
                re.sub(r's+', ' ', header.strip())
            )

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

            with label.canvas.before:
                Color(rgba=[1,1,0,1])
                Rectangle(pos=label.pos, size = label.size)


            self.add_widget(label)

        text_args = {
            'size_hint': (1,None),
            'background_normal':'resources/images/blank.png',
            'background_active':'resources/images/blank.png',
            'text':'Enter Text Here'
        }

        body = self.__segment.get_text()
        if body:
            text_args['text'] = body

        text_input = TextInput(**text_args)
        text_input.height = text_input.minimum_height
        text_input.bind(minimum_height=text_input.setter('height'))
        self.add_widget(text_input)



لینک منبع

برچسب‌ها:
  • نویسنده
    A-brand
  • تعداد بازدید
    2 views
0دیدگاه فرستاده شده است.
شما هم دیدگاه خود را بنویسید