'how to set up scrollview for a label in a boxlayout

here is my code

     BoxLayout:
        size_hint: 1, 4
        BoxLayout:
            size_hint: .15, 1
        ScrollView:
            id: sc
            scroll_type:["bars"]
            bar_width: 10
            bar_color: 1,0,0
            BoxLayout:
                size_hint:(1, None)
                height:self.minimum_height
                #size_hint: 1, 1
                Label:
                    #height: sc.height
                    #height:self.height
                    size_hint:(1, None)
                    id: nt
                    color: 1,1,1
                    text:root.textn
                    font_size: "20sp"
                    text_size: self.size
                    valign: "top"
                    halign: "left"
        BoxLayout:
            size_hint: .15, 1

with the above code i get this enter image description here

it does not show the whole text and the scrollview does not come into effect what can i do?



Solution 1:[1]

Here is a modified version of your kv that I think will work for you:

BoxLayout:
    # size_hint: 1, 4   # this would make the BoxLayout 4 times taller than its parent???
    BoxLayout:
        size_hint: .15, 1
    ScrollView:
        id: sc
        size_hint: 1, 0.5
        scroll_type:["bars"]
        bar_width: 10
        bar_color: 1,0,0
        BoxLayout:
            size_hint:(1, None)
            height:self.minimum_height
            Label:
                size_hint:(1, None)
                height: self.texture_size[1]   # this makes the Label fit to height of text
                id: nt
                color: 1,1,1
                text:app.textn
                font_size: "20sp"
                # text_size: self.size   # not needed
                valign: "top"
                halign: "left"
    BoxLayout:
        size_hint: .15, 1

The main point is setting the height of the Label to adjust to its text.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 John Anderson