0

I'm a Python beginner, and I was trying to build a Youtube Downloader. I just needed a GUI for easy usage. So I decided on Kivy.

In the GUI I have this label named self.labelOutput. It is placed under a button. The script is very basic, so pressing the button only echoes the input.

The problem is that this label is displaying weird behaviour (for me at least). It grows when multiple lines are entered (next step would be word wrapping). But the label seems to be growing upward, instead of downward. Like it's position is pinned at its bottom. Or as if my app only use half of the screen. I have searched the interwebs, including this site, but, while there are a lot of issues with labels, my particular issue is not here yet. I even asked AI generators, but that made my code only more messy.

From CSS I remember certain attributes don't work properly when other properties aren't set or set wrong. Maybe it's something like that.

I hope you guys can help.

This is my code so far (far from pretty or efficient, I know. It's mostly AI generated to get started):

import kivy
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.scrollview import ScrollView

class MyApp(App):
    def build(self):
        float_layout = FloatLayout()
        # Make a BoxLayout to organiseren the widgets
        box_layout = BoxLayout(orientation='vertical', size_hint=(1, None), pos_hint={'top': 0.78})

        # Make a Label to display text
        self.label = Label(text="YTDownloader", font_size=90, size_hint_y=None,  height=100)
        box_layout.add_widget(self.label)
        
        self.label2 = Label(text="Youtube Downloader", size_hint_y=None,  height=100)
        box_layout.add_widget(self.label2)
        #spacer label
        self.label3 = Label(text="", size_hint_y=None,  height=20)
        box_layout.add_widget(self.label3)

        # Make a TextInput-widget
        self.text_input = TextInput(hint_text="Voer zoektermen in...", size_hint=(None,  None), height=100, width=900, pos_hint={'center_x': 0.5}, padding=(20,20))
        box_layout.add_widget(self.text_input)
        #another spacer label
        self.label4 = Label(text="", size_hint_y=None,  height=30)
        box_layout.add_widget(self.label4)

        # Make a Button-widget
        button = Button(text="Zoek!", size_hint=(None,  None), height=100, width=300, pos_hint={'center_x': 0.5})
        # connect a function to the button
        button.bind(on_press=self.on_button_press)
        box_layout.add_widget(button)

        self.labelOutput = Label(text="", size_hint_y=None, width=960, text_size=(960, None), valign='top')
        self.labelOutput.bind(texture_size=self.update_label_height)
        box_layout.add_widget(self.labelOutput)
        
        float_layout.add_widget(box_layout)

        return float_layout

    def on_button_press(self, instance):
        # get the input text and display it in the output label
        input_text = self.text_input.text
        self.labelOutput.text = f"You entered: {input_text}"
        
    def update_label_height(self, instance, value):
        instance.height = instance.texture_size[1]

if __name__ == "__main__":
    MyApp().run()
1
  • The position of the Label is pinned to the bottom of the BoxLayout, so it can only grow upward. Commented Mar 26 at 20:52

1 Answer 1

0

Adding scrollview was the solution.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.