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

    <tfoot id='t35FA'></tfoot>

      <legend id='t35FA'><style id='t35FA'><dir id='t35FA'><q id='t35FA'></q></dir></style></legend>

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

      1. 如何将多列放入 kivy RecycleView?

        时间:2023-10-10

              <tbody id='kLVZs'></tbody>

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

          1. <tfoot id='kLVZs'></tfoot>
                • <bdo id='kLVZs'></bdo><ul id='kLVZs'></ul>

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

                  本文介绍了如何将多列放入 kivy RecycleView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想将(csv-)表的数据放入 kivy recycleview.

                  如果我将固定文本分配给 kv 中的标签,我设法在一行中插入多个列,但我无法让它用字典列表中的数据填充标签.到目前为止,这是我用来测试概念的代码:

                  from kivy.app import App从 kivy.lang 导入生成器从 kivy.uix.recycleview 导入 RecycleView从 kivy.uix.boxlayout 导入 BoxLayout导入 csvitems = [{'SP1': 'Artikelnummer', 'SP2': '姓名', 'SP3': 'Groesse'},{'SP1': '510001', 'SP2': '大泵', 'SP3': '1.50 L'},{'SP1':'523001','SP2':'Leonie Still','SP3':'1.50 L'},{'SP1':'641301','SP2':'可乐混合','SP3':'1.50 L'}]类表(BoxLayout):def __init__(self, **kwargs):super(Tabelle, self).__init__(**kwargs)def insert_SP(自我,数据):对于数据中的 i:self.spalte1_SP = i['SP1']#print(self.spalte1_SP)self.spalte2_SP = i['SP2']self.spalte3_SP = i['SP3']builder.load_string('''<塔贝尔>:方向:水平"spalte1_SP: 'spalte1'spalte2_SP: 'spalte2'spalte3_SP: 'spalte3'标签:编号:Spalte1文本:root.spalte1_SP标签:编号:Spalte2文本:root.spalte2_SP标签:编号:Spalte3文本:root.spalte3_SP<房车>:视图类:塔贝尔"回收箱布局:default_size:无,dp(20)default_size_hint:1,无size_hint_y:无高度:self.minimum_height方向:垂直"''')房车类(回收视图):def __init__(self, **kwargs):超级(房车,自我).__init__(**kwargs)#self.data = []x = 表()x.insert_SP(项目)类测试应用程序(应用程序):定义构建(自我):返回 RV()如果 __name__ == '__main__':TestApp().run()

                  我希望在 3 列中看到来自 items 的数据,但由于某种原因它们保持为空.

                  解决方案

                  它是空的,因为 data 没有填充.

                  解决方案

                  • 删除 class Tabelle()
                  • 中的所有编码
                  • pass 添加到 class Tabelle()
                  • 将以下内容添加到 class RV()
                  • 的构造函数中,__init__()

                  片段

                  self.data = [{'spalte1_SP': str(x['SP1']), 'spalte2_SP': str(x['SP2']), 'spalte3_SP': str(x['SP3'])} for x in items]

                  I want to put the data of a (csv-)table into a kivy recycleview.

                  I managed to insert multiple columns with one row, if i assign a fixed text to the Labels in the kv, but i can't get it to fill the labels with data from a dictionary list. This is the code so far, that i use to test the concept:

                  from kivy.app import App
                  from kivy.lang import Builder
                  from kivy.uix.recycleview import RecycleView
                  from kivy.uix.boxlayout import BoxLayout
                  import csv
                  
                  items = [{'SP1': 'Artikelnummer', 'SP2': 'Name', 'SP3': 'Groesse'},
                      {'SP1': '510001', 'SP2': 'Big Pump', 'SP3': '1.50 L'},
                      {'SP1': '523001', 'SP2': 'Leonie Still', 'SP3': '1.50 L'},
                      {'SP1': '641301', 'SP2': 'Cola Mix', 'SP3': '1.50 L'}
                  ]
                  
                  class Tabelle(BoxLayout):
                      def __init__(self, **kwargs):
                          super(Tabelle, self).__init__(**kwargs)
                  
                      def insert_SP(self, data):
                          for i in data:
                              self.spalte1_SP = i['SP1']
                              #print(self.spalte1_SP)
                              self.spalte2_SP = i['SP2']
                              self.spalte3_SP = i['SP3']
                  
                  Builder.load_string('''
                  <Tabelle>:
                      orientation: 'horizontal'
                      spalte1_SP: 'spalte1'
                      spalte2_SP: 'spalte2'
                      spalte3_SP: 'spalte3'
                      Label:
                          id: Spalte1
                          text: root.spalte1_SP
                      Label:
                          id: Spalte2
                          text: root.spalte2_SP
                      Label:
                          id: Spalte3
                          text: root.spalte3_SP
                  
                  <RV>:
                      viewclass: 'Tabelle'
                      RecycleBoxLayout:
                          default_size: None, dp(20)
                          default_size_hint: 1, None
                          size_hint_y: None
                          height: self.minimum_height
                          orientation: 'vertical'
                  ''')
                  
                  class RV(RecycleView):
                      def __init__(self, **kwargs):
                          super(RV, self).__init__(**kwargs)
                          #self.data = []
                          x = Tabelle()
                          x.insert_SP(items)
                  
                  class TestApp(App):
                      def build(self):
                          return RV()
                  
                  if __name__ == '__main__':
                      TestApp().run()
                  

                  I expect to see the data from items in 3 columns, but they stay empty for some reason.

                  解决方案

                  It is empty because data was not populated.

                  Solution

                  • Remove all codings in class Tabelle()
                  • Add pass into class Tabelle()
                  • Add the following into constructor, __init__() of class RV()

                  Snippets

                  self.data = [{'spalte1_SP': str(x['SP1']), 'spalte2_SP': str(x['SP2']), 'spalte3_SP': str(x['SP3'])} for x in items]
                  

                  Kivy RecycleView » data

                  The view is generatad by processing the data, essentially a list of dicts, and uses these dicts to generate instances of the viewclass as required.

                  data
                  

                  The data used by the current view adapter. This is a list of dicts whose keys map to the corresponding property names of the viewclass.

                  data is an AliasProperty that gets and sets the data used to generate the views.

                  Example

                  main.py

                  from kivy.app import App
                  from kivy.lang import Builder
                  from kivy.uix.recycleview import RecycleView
                  from kivy.uix.boxlayout import BoxLayout
                  
                  items = [{'SP1': 'Artikelnummer', 'SP2': 'Name', 'SP3': 'Groesse'},
                           {'SP1': '510001', 'SP2': 'Big Pump', 'SP3': '1.50 L'},
                           {'SP1': '523001', 'SP2': 'Leonie Still', 'SP3': '1.50 L'},
                           {'SP1': '641301', 'SP2': 'Cola Mix', 'SP3': '1.50 L'}
                           ]
                  
                  
                  class Tabelle(BoxLayout):
                      pass
                  
                  
                  Builder.load_string('''
                  <Tabelle>:
                      orientation: 'horizontal'
                      spalte1_SP: 'spalte1'
                      spalte2_SP: 'spalte2'
                      spalte3_SP: 'spalte3'
                      Label:
                          id: SP1
                          text: root.spalte1_SP
                      Label:
                          id: SP2
                          text: root.spalte2_SP
                      Label:
                          id: SP3
                          text: root.spalte3_SP
                  
                  <RV>:
                      viewclass: 'Tabelle'
                      RecycleBoxLayout:
                          default_size: None, dp(20)
                          default_size_hint: 1, None
                          size_hint_y: None
                          height: self.minimum_height
                          orientation: 'vertical'
                  ''')
                  
                  
                  class RV(RecycleView):
                      def __init__(self, **kwargs):
                          super(RV, self).__init__(**kwargs)
                          self.data = [{'spalte1_SP': str(x['SP1']), 'spalte2_SP': str(x['SP2']), 'spalte3_SP': str(x['SP3'])} for x in items]
                  
                  
                  class TestApp(App):
                      def build(self):
                          return RV()
                  
                  
                  if __name__ == '__main__':
                      TestApp().run()
                  

                  Output

                  这篇关于如何将多列放入 kivy RecycleView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Kivy 错误:[CRITICAL] [App] 无法获取窗口,中止 下一篇:Kivy 属性错误 - 对象没有属性 - 尝试以 kv 语言连

                  相关文章

                  最新文章

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

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

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