【问题标题】:Kivy adding text to ScrollViewKivy 向 ScrollView 添加文本
【发布时间】:2021-01-12 01:18:44
【问题描述】:

我正在用 kivy 编写一个字典应用程序。我想从 textinput 获取文本并创建一个滚动视图小部件并将结果添加到小部件。

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()

【问题讨论】:

标签: python kivy


【解决方案1】:

首先要从您的TextInput 使用self.input_.text 获取文本,它会在您的文本输入中为您提供文本。在您的 self.search 函数中使用它。然后你可以通过任何你想要的方式得到结果。然后要将它们添加到列表中,您必须使用ListView,然后在每个项目的列表视图中添加ListItems。更多详情可以查看kivydocs

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-29
    • 2017-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多