'Kivy Label texture_size height changing for texts of same number of lines

I have a label I want to customize to wrap text to a constant width, implemented as below:

<RisingTextUser@Label>:
    id: user_label
    canvas.before:
        BorderImage:
            source: 'resources/bubble.png'
            size: self.size
            pos: self.pos
            border: 8, 9, 7, 7
    y_hint: 1
    pos_hint: {"right": 1, "top": self.y_hint}
    size_hint: 0.8, None
    text_size: root.width, None
    height: self.texture_size[1]
    padding: 10, 10
    opacity: 0
    text: "Some text"
    color: 0, 0, 0, 1

On its own, this looks how I want it to. Text takes up space until it is as wide as the label, then it wraps to a new line and, if necessary, the label becomes taller to match. The issue is that when I try to access user_label.height, or user_label.texture_size[1] in Python, the value returned varies even for text of the same number of lines which look identical in the app. For example "one line" has a height of 38, while "one even longer line" has a height of 56, despite still only being one line. I want to use the height in animation, and with it varying and not matching the actual height of the widget, that is not going to work.

I should point out that this label is in a FloatLayout, and that when I do not specify any size_hint, it is narrower and the text takes up the height reported by the above accessors.



Sources

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

Source: Stack Overflow

Solution Source