Skip to content
Advertisement

Kivy adding text to ScrollView

I’m coding a dictionary app with kivy. I want to get text from textinput and create a scrollview widget and add results to widget.

class dictionary(App):
def build(self):
    self.layout = BoxLayout(orientation="vertical")
    self.first_row = BoxLayout(orientation="horizontal", size_hint_y=1)
    self.examples = BoxLayout(orientation="vertical", size_hint_y=10)

    self.input_ = TextInput(hint_text="Search on ludwig.guru",
                            multiline=False,
                            size_hint_x=2,
                            size_hint_y=1)

    self.search_button = Button(text="Search",
                                on_press=self.search,
                                size_hint_x=1,
                                size_hint_y=1)     

    self.first_row.add_widget(self.input_)
    self.first_row.add_widget(self.search_button)
    self.layout.add_widget(self.first_row)
    self.layout.add_widget(self.examples)

    return self.layout

if name == "__main__":
    dictionary.run()

Advertisement

Answer

First of all to get the text from your TextInput use self.input_.text, it will give you the text in your text input. Use this in your self.search function. Then you can get the results by whatever means you want to. Then to add them to a list you have to use a ListView then add ListItems inside that list view for each item. You can check kivy docs for more details.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement