Fomalhaut
Fomalhaut

Reputation: 9727

How to expand label height in KivyMD?

I want to make the label height dynamically expanded depending on the size of text inside. I tried this:

from kivymd.label import MDLabel

label = MDLabel(
    text="My looooooooooong text",
    width=500,
    size_hint=(None, None)
)

But the height of this label is fixed and the text is shown deformed. How to make the height expanded?

I am using Python 3 and KivyMD library.

Upvotes: 0

Views: 2798

Answers (2)

SUNNETDev
SUNNETDev

Reputation: 1

To make your mdlabel expand with the text, set the height property to this: height=self.texture_size[1]

However, you must understand that the containing parent widget must also have self.minimum_height as its height and None size_hint_y to accomodate the expansion of its child widget

Upvotes: 0

Oluwafemi Sule
Oluwafemi Sule

Reputation: 38922

The MDLabel class inherits from kivy.uix.Label. All arguments you'll pass normally to kivy.uix.Label can be passed to the MDLabel. Checking the constructor for MDLabel validates this.

To make a label with unlimited height, you'll construct the Label like so:

label = MDLabel(text='My looooooooooong text', text_size=(500, None))

Reference:

Upvotes: 0

Related Questions