KivyMD Button Wrap text

263 views
Skip to first unread message

Eoin Brennan

unread,
Sep 6, 2022, 1:14:11 PM9/6/22
to Kivy users support
so, I am hoping that there is a simple answer to this as I have already posted a question earlier and dont want to be over doing it!!

In Kivy to wrap text in a button you can use:

KV
Button:
    text_size: self.width, None
    height: self.texture_size[1]

Tryin to achieve the same thing in KivyMD, is this possible? I am getting the error that the Button has no attribute texture_size. Is text handled differently in KivyMD??

Thanks

Eoin

Elliot Garbus

unread,
Sep 6, 2022, 1:31:33 PM9/6/22
to kivy-...@googlegroups.com
I don’t know off the top of my head. Kivymd is just a set of custom widget built on kivy. I suggest you look at the source code. 



Sent from my iPhone

On Sep 6, 2022, at 10:14 AM, Eoin Brennan <eoinbr...@gmail.com> wrote:

so, I am hoping that there is a simple answer to this as I have already posted a question earlier and dont want to be over doing it!!
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/b65b31be-859d-4350-a416-4e7b4d0c055dn%40googlegroups.com.

Eoin Brennan

unread,
Sep 7, 2022, 5:05:34 AM9/7/22
to Kivy users support
So, after alot of poking around I discovered that the Kivy Button inherits from the Label class and the Label call has a "texture_uppdate" method that is called when the screen size changes for example and it redraws the text to fit in the button if the right values are set to your Button!!

In KivyMD, the buttons don't inherit from the MdLabel, instead they inherit from  a class, "ButtonContentsText". This class has nothing in it so I am not sure how it operates. There is no methods or properties in tha class definition, its just blank! 

Strangely enough though, the "MDTextButton" does inherit from the MDLabel and it will wrap the text if the label is resized!! 

Not too sure where to go now!!

Elliot Garbus

unread,
Sep 7, 2022, 1:42:19 PM9/7/22
to kivy-...@googlegroups.com

ButtonContextText is defined in KV: https://github.com/kivymd/KivyMD/blob/ffeb54dbbfc4d49b13402608499345118979a7a5/kivymd/uix/button/button.kv#L34

 

You can see in the code the id used for the MDLabel that holds the text. 

Eoin Brennan

unread,
Sep 9, 2022, 2:37:12 PM9/9/22
to Kivy users support
Of course, never thought of looking through the kv file!!  Makes sense!!

While reading thorough comments on the kivymd git page it was said that multi lines buttons are not allowed per MD3 i think it was so it turns out that it's a feature of kivymd that you can't do this!! So I think to achieve what I want i'm going to have to dive into that KV file, I reckon the answer is in there!! 

Thanks for this!!

Eoin
Reply all
Reply to author
Forward
0 new messages