Reputation: 9727
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
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
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))
Upvotes: 0