Bohr Bohr -4 years ago 56
Python Question

Kivy Label and Popup + long text

So I am trying to show some long text in a Popup. It would be ideal if the height of the Popup could change for the length of text. But that's not my only problem I've tried to implement this without the size change with this code

boxl = uix.boxlayout.BoxLayout(orientation="vertical")
boxl2 = uix.boxlayout.BoxLayout(orientation="horizontal")
pop = Popup(title="Title", content=boxl, size_hint=(0.75,0.8))
text = "Really long text"

document = uix.label.Label(text=text,markup=True, valign='top')

button = uix.button.Button(text='back', size_hint_y=None, height=40)
button2 = uix.button.Button(text="Button Title", size_hint_y=None, height=40)
button.bind(on_press=(lambda x:pop.dismiss()))
button2.bind(on_press=(lambda x,data=data:(self.set_vorteil(data),pop.dismiss())))
boxl.add_widget(document)

boxl2.add_widget(button)
boxl2.add_widget(button2)
boxl.add_widget(boxl2)
document.bind(size=document.setter('text_size'))
pop.open()


The interesting thing with this is that my text is cut off, even if there is a huge free space before the buttons. How do I fix this or even make it right? I'm confused with Kivy's way of using Labels.

Answer Source

The reason why you get so much free space between the Label and the Button widgets is that the two BoxLayout widgets (boxl and boxl2) are actually splitting the space in half (even if you don't notice it). If you want your Label to have all that space, you'll need to set the height of the boxl2 widget:

boxl2 = BoxLayout(orientation="horizontal", size_hint_y=None, height=40)

This sets the boxl2 widget to the same height as the Button widgets

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download