<bdo id='UjUbY'></bdo><ul id='UjUbY'></ul>
  • <legend id='UjUbY'><style id='UjUbY'><dir id='UjUbY'><q id='UjUbY'></q></dir></style></legend>
    <tfoot id='UjUbY'></tfoot>

        <i id='UjUbY'><tr id='UjUbY'><dt id='UjUbY'><q id='UjUbY'><span id='UjUbY'><b id='UjUbY'><form id='UjUbY'><ins id='UjUbY'></ins><ul id='UjUbY'></ul><sub id='UjUbY'></sub></form><legend id='UjUbY'></legend><bdo id='UjUbY'><pre id='UjUbY'><center id='UjUbY'></center></pre></bdo></b><th id='UjUbY'></th></span></q></dt></tr></i><div id='UjUbY'><tfoot id='UjUbY'></tfoot><dl id='UjUbY'><fieldset id='UjUbY'></fieldset></dl></div>

        <small id='UjUbY'></small><noframes id='UjUbY'>

      1. Python Kivy ListView:如何删除选定的 ListItemButton?

        时间:2023-10-09

        <small id='iiawI'></small><noframes id='iiawI'>

          <bdo id='iiawI'></bdo><ul id='iiawI'></ul>

            • <tfoot id='iiawI'></tfoot>
                <tbody id='iiawI'></tbody>

              <i id='iiawI'><tr id='iiawI'><dt id='iiawI'><q id='iiawI'><span id='iiawI'><b id='iiawI'><form id='iiawI'><ins id='iiawI'></ins><ul id='iiawI'></ul><sub id='iiawI'></sub></form><legend id='iiawI'></legend><bdo id='iiawI'><pre id='iiawI'><center id='iiawI'></center></pre></bdo></b><th id='iiawI'></th></span></q></dt></tr></i><div id='iiawI'><tfoot id='iiawI'></tfoot><dl id='iiawI'><fieldset id='iiawI'></fieldset></dl></div>
                <legend id='iiawI'><style id='iiawI'><dir id='iiawI'><q id='iiawI'></q></dir></style></legend>

                1. 本文介绍了Python Kivy ListView:如何删除选定的 ListItemButton?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试通过构建一个简单的待办事项列表应用程序来学习 kivy,就像在 Kivy 中创建应用程序"一书的作者 Dusty Phillips 所建议的那样.

                  I'm trying to learn kivy by building a simple todo-list app like suggested by Dusty Phillips, author of the book "Creating apps in Kivy".

                  这是目前为止的代码:

                  from kivy.app import App
                  from kivy.uix.boxlayout import BoxLayout
                  from kivy.properties import ObjectProperty
                  from kivy.uix.listview import ListItemButton
                  
                  
                  class TaskButton(ListItemButton):
                      pass
                  
                  
                  class TodoRoot(BoxLayout):
                      task_input = ObjectProperty()
                      task_list = ObjectProperty()
                  
                      def add_task(self):
                          self.task_list.adapter.data.extend([self.task_input.text])
                          self.task_list._trigger_reset_populate()
                  
                      def del_task(self):
                          pass
                  
                  
                  class TodoApp(App):
                      def build(self):
                          return TodoRoot()
                  
                  
                  if __name__ == '__main__':
                      TodoApp().run()
                  

                  这是kv文件:

                  #: import main todo
                  #: import ListAdapter kivy.adapters.listadapter.ListAdapter
                  #: import ListItemButton kivy.uix.listview.ListItemButton
                  
                  TodoRoot:
                  
                  <TodoRoot>:
                      orientation: "vertical"
                      task_input: task_input_view
                      task_list: tasks_list_view
                  
                      BoxLayout:
                          size_hint_y: None
                          height: "40dp"
                  
                          TextInput:
                              id: task_input_view
                              size_hint_x: 70
                          Button:
                              text: "Add"
                              size_hint_x: 15
                              on_press: root.add_task()
                          Button:
                              text: "Del"
                              size_hint_x: 15
                              on_press: root.del_task()
                      ListView:
                          id: tasks_list_view
                          adapter:
                              ListAdapter(data=[], cls=main.TaskButton)
                  

                  这是它的样子:

                  我知道 ListView API 仍处于试验阶段,我抱怨有关使用适配器/转换器、google &所以搜索也没有帮助.那么需要什么代码才能使 Del-Button 工作并删除选定的 ListItemButton?

                  I know the ListView API is still somewhat experimental and I'm complaining about the examples on using adapters / converters, google & SO search didn't help either. So what code is needed to make the Del-Button work and remove a selected ListItemButton?

                  推荐答案

                  大量阅读 ListView API docs &例子,我终于找到了自己.我们需要的是listadapter-Class的selection-Property,那么我们可以简单的调用adapter.data-ListProperty继承的remove方法.

                  After a lot of reading ListView API docs & examples, I finally found out myself. What we need is the selection-Property of the listadapter-Class, then we can simply call the inherited remove method of the adapter.data-ListProperty.

                  所以对于任何有兴趣的人来说,这是代码:

                  So for anyone interesested this is the code:

                  def del_task(self, *args):
                      if self.task_list.adapter.selection:
                          selection = self.task_list.adapter.selection[0].text
                          self.task_list.adapter.data.remove(selection)
                          self.task_list._trigger_reset_populate()
                  

                  这篇关于Python Kivy ListView:如何删除选定的 ListItemButton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Kivy'对象没有属性'错误 下一篇:在 Kivy 中显示一个 numpy 数组

                  相关文章

                  最新文章

                  • <bdo id='JLRkl'></bdo><ul id='JLRkl'></ul>

                    1. <small id='JLRkl'></small><noframes id='JLRkl'>

                      <i id='JLRkl'><tr id='JLRkl'><dt id='JLRkl'><q id='JLRkl'><span id='JLRkl'><b id='JLRkl'><form id='JLRkl'><ins id='JLRkl'></ins><ul id='JLRkl'></ul><sub id='JLRkl'></sub></form><legend id='JLRkl'></legend><bdo id='JLRkl'><pre id='JLRkl'><center id='JLRkl'></center></pre></bdo></b><th id='JLRkl'></th></span></q></dt></tr></i><div id='JLRkl'><tfoot id='JLRkl'></tfoot><dl id='JLRkl'><fieldset id='JLRkl'></fieldset></dl></div>
                    2. <legend id='JLRkl'><style id='JLRkl'><dir id='JLRkl'><q id='JLRkl'></q></dir></style></legend>
                    3. <tfoot id='JLRkl'></tfoot>