Set button/label text width to fit the outer boundaries [Troubleshooting: Kivy]

Spread the word!

I will assume you have some background knowledge about the Kivy program structure (otherwise, visit this post).

Case #1

In this example the button will be added from the .py script to a BoxLayout defined in the .kv file. Make sure that your BoxLayout has a width (here 150 px) property and None size_hint_x:

In your Python code, when you create a button and add it to the previous defined BoxLayout, set the text_size property according to its width (here the 80% percent):

Case #2

If you need to set the width of a widget to its text, you may simply add this line in your .kv file inside the corresponding widget:

Be the first to comment

Leave a Reply

Your email address will not be published.


*