I have three buttons (one column, three rows) in a GridLayout. The text on the top of the button is centered but when it is too long it extends past the screen. How do I wrap it? Current code is:
self.add_widget(Button(text="", text_size = (None, self.height), halign = "center", valign = "center"))
for each of the buttons.
CodePudding user response:
Setting
text_size = (None, self.height)
as an arg to the Button
constructor does not set up a binding. It just sets the text_size
to the values at the moment that the Button
__init__()
method is executed. So the text_size
gets set to (None, 100)
and stays that way (the default height
of a widget is 100
). If you want to actually have such a binding, you must either use the Kivy
language, or set up the binding yourself. Something like this:
butt = Button(text="", text_size = self.size, halign = "center", valign = "center")
butt.bind(size=self.resize)
self.add_widget(butt)
def resize(self, butt, new_size):
butt.text_size = new_size