久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <legend id='LHdXi'><style id='LHdXi'><dir id='LHdXi'><q id='LHdXi'></q></dir></style></legend>

      <tfoot id='LHdXi'></tfoot>

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

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

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

      1. Kivy - python - recycleview 行中的多個小部件

        Kivy - python - multiple widgets in recycleview row(Kivy - python - recycleview 行中的多個小部件)

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

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

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

              1. <legend id='vflS4'><style id='vflS4'><dir id='vflS4'><q id='vflS4'></q></dir></style></legend><tfoot id='vflS4'></tfoot>
                  本文介紹了Kivy - python - recycleview 行中的多個小部件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  I would like to make a recycleview that has multiple labels in each recycleview row. In my specfic example I would like to have 3 labels in each row: 1 label containing the item index, one label containing an item from one dataset, and another label from another dataset

                  In this example (taken from the kivy examples) we have a recycleview where each row in the recycleview contains a single label:

                  from kivy.app import App
                  from kivy.lang import Builder
                  from kivy.uix.recycleview import RecycleView
                  from kivy.uix.recycleview.views import RecycleDataViewBehavior
                  from kivy.uix.label import Label
                  from kivy.properties import BooleanProperty
                  from kivy.uix.recycleboxlayout import RecycleBoxLayout
                  from kivy.uix.behaviors import FocusBehavior
                  from kivy.uix.recycleview.layout import LayoutSelectionBehavior
                  
                  Builder.load_string('''
                  <SelectableLabel>:
                      # Draw a background to indicate selection
                      canvas.before:
                          Color:
                              rgba: (.0, 0.9, .1, .3) if self.selected else (0, 0, 0, 1)
                          Rectangle:
                              pos: self.pos
                              size: self.size
                  <RV>:
                      viewclass: 'SelectableLabel'
                      SelectableRecycleBoxLayout:
                          default_size: None, dp(56)
                          default_size_hint: 1, None
                          size_hint_y: None
                          height: self.minimum_height
                          orientation: 'vertical'
                          multiselect: True
                          touch_multiselect: True
                  ''')
                  
                  
                  items_1= {'apple', 'banana', 'pear', 'pineapple'}
                  items_2= {'dog', 'cat', 'rat', 'bat'}
                  
                  class SelectableRecycleBoxLayout(FocusBehavior, LayoutSelectionBehavior,
                                                   RecycleBoxLayout):
                      ''' Adds selection and focus behaviour to the view. '''
                  
                  
                  class SelectableLabel(RecycleDataViewBehavior, Label):
                      ''' Add selection support to the Label '''
                      index = None
                      selected = BooleanProperty(False)
                      selectable = BooleanProperty(True)
                  
                      def refresh_view_attrs(self, rv, index, data):
                          ''' Catch and handle the view changes '''
                          self.index = index
                          return super(SelectableLabel, self).refresh_view_attrs(
                              rv, index, data)
                  
                      def on_touch_down(self, touch):
                          ''' Add selection on touch down '''
                          if super(SelectableLabel, self).on_touch_down(touch):
                              return True
                          if self.collide_point(*touch.pos) and self.selectable:
                              return self.parent.select_with_touch(self.index, touch)
                  
                      def apply_selection(self, rv, index, is_selected):
                          ''' Respond to the selection of items in the view. '''
                          self.selected = is_selected
                          if is_selected:
                              print("selection changed to {0}".format(rv.data[index]))
                          else:
                              print("selection removed for {0}".format(rv.data[index]))
                  
                  
                  class RV(RecycleView):
                      def __init__(self, **kwargs):
                          super(RV, self).__init__(**kwargs)
                          self.data = [{'text': str(x)} for x in items_1]
                  
                  
                  class TestApp(App):
                      def build(self):
                          return RV()
                  
                  if __name__ == '__main__':
                      TestApp().run()
                  

                  I would like each recycleview row to have 3 labels: first label is the index, second label is items_1 and third label is items_2. Like this:

                  0 apple dog

                  1 banana cat

                  2 pear rat

                  3 pineapple bat

                  Thank you!

                  解決方案

                  I was looking for a similar solution and could not find it. I do not think PalimPalim has really answered the question since I think the Ben t was looking for multiple label widgets treated as a single line.

                  In this case you use a custom widget for GridLayout and specify it's structure.

                  <SelectableLabel>:
                  # Draw a background to indicate selection
                  canvas.before:
                      Color:
                          rgba: (.0, 0.9, .1, .3) if self.selected else (0, 0, 0, 1)
                      Rectangle:
                          pos: self.pos
                          size: self.size
                  label1_text: 'label 1 text'
                  label2_text: 'label 2 text'
                  label3_text: 'label 3 text'
                  pos: self.pos
                  size: self.size
                  Label:
                      id: id_label1
                      text: root.label1_text
                  Label:
                      id: id_label2
                      text: root.label2_text
                  Label:
                      id: id_label3
                      text: root.label3_text
                  

                  In applying your data into the RV, you will need to restructure the dictionary to reflect the label layout

                  class RV(RecycleView):
                  def __init__(self, **kwargs):
                      super(RV, self).__init__(**kwargs)
                      paired_iter = zip(items_1, items_2)
                      self.data = []
                      for i1, i2 in paired_iter:
                          d = {'label2': {'text': i1}, 'label3': {'text': i2}}
                          self.data.append(d)
                  

                  Finally in the refresh_view_attrs, you will specify .label_text which is bound to each label, or you can use label id's.

                  def refresh_view_attrs(self, rv, index, data):
                      ''' Catch and handle the view changes '''
                      self.index = index
                      self.label1_text = str(index)
                      self.label2_text = data['label2']['text']
                      self.ids['id_label3'].text = data['label3']['text']  # As an alternate method of assignment
                      return super(SelectableLabel, self).refresh_view_attrs(
                          rv, index, data)
                  

                  The entire code is below:

                  from kivy.app import App
                  from kivy.lang import Builder
                  from kivy.uix.recycleview import RecycleView
                  from kivy.uix.recycleview.views import RecycleDataViewBehavior
                  from kivy.uix.label import Label
                  from kivy.uix.gridlayout import GridLayout
                  from kivy.properties import BooleanProperty
                  from kivy.uix.recycleboxlayout import RecycleBoxLayout
                  from kivy.uix.behaviors import FocusBehavior
                  from kivy.uix.recycleview.layout import LayoutSelectionBehavior
                  
                  Builder.load_string('''
                  <SelectableLabel>:
                      # Draw a background to indicate selection
                      canvas.before:
                          Color:
                              rgba: (.0, 0.9, .1, .3) if self.selected else (0, 0, 0, 1)
                          Rectangle:
                              pos: self.pos
                              size: self.size
                      label1_text: 'label 1 text'
                      label2_text: 'label 2 text'
                      label3_text: 'label 3 text'
                      pos: self.pos
                      size: self.size
                      Label:
                          id: id_label1
                          text: root.label1_text
                      Label:
                          id: id_label2
                          text: root.label2_text
                      Label:
                          id: id_label3
                          text: root.label3_text
                  
                  <RV>:
                      viewclass: 'SelectableLabel'
                      SelectableRecycleBoxLayout:
                          default_size: None, dp(56)
                          default_size_hint: 1, None
                          size_hint_y: None
                          height: self.minimum_height
                          orientation: 'vertical'
                          multiselect: True
                          touch_multiselect: True
                  ''')
                  
                  
                  items_1 = {'apple', 'banana', 'pear', 'pineapple'}
                  items_2 = {'dog', 'cat', 'rat', 'bat'}
                  
                  
                  class SelectableRecycleBoxLayout(FocusBehavior, LayoutSelectionBehavior,
                                                   RecycleBoxLayout):
                      ''' Adds selection and focus behaviour to the view. '''
                  
                  
                  class SelectableLabel(RecycleDataViewBehavior, GridLayout):
                      ''' Add selection support to the Label '''
                      index = None
                      selected = BooleanProperty(False)
                      selectable = BooleanProperty(True)
                      cols = 3
                  
                      def refresh_view_attrs(self, rv, index, data):
                          ''' Catch and handle the view changes '''
                          self.index = index
                          self.label1_text = str(index)
                          self.label2_text = data['label2']['text']
                          self.ids['id_label3'].text = data['label3']['text']  # As an alternate method of assignment
                          return super(SelectableLabel, self).refresh_view_attrs(
                              rv, index, data)
                  
                      def on_touch_down(self, touch):
                          ''' Add selection on touch down '''
                          if super(SelectableLabel, self).on_touch_down(touch):
                              return True
                          if self.collide_point(*touch.pos) and self.selectable:
                              return self.parent.select_with_touch(self.index, touch)
                  
                      def apply_selection(self, rv, index, is_selected):
                          ''' Respond to the selection of items in the view. '''
                          self.selected = is_selected
                          if is_selected:
                              print("selection changed to {0}".format(rv.data[index]))
                          else:
                              print("selection removed for {0}".format(rv.data[index]))
                  
                  
                  class RV(RecycleView):
                      def __init__(self, **kwargs):
                          super(RV, self).__init__(**kwargs)
                          paired_iter = zip(items_1, items_2)
                          self.data = []
                          for i1, i2 in paired_iter:
                              d = {'label2': {'text': i1}, 'label3': {'text': i2}}
                              self.data.append(d)
                          # can also be performed in a complicated one liner for those who like it tricky
                          # self.data = [{'label2': {'text': i1}, 'label3': {'text': i2}} for i1, i2 in zip(items_1, items_2)]
                  
                  
                  class TestApp(App):
                      def build(self):
                          return RV()
                  
                  if __name__ == '__main__':
                      TestApp().run()
                  

                  這篇關于Kivy - python - recycleview 行中的多個小部件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to make a discord bot that gives roles in Python?(如何制作一個在 Python 中提供角色的不和諧機器人?)
                  Discord bot isn#39;t responding to commands(Discord 機器人沒有響應命令)
                  Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“關于我嗎?Discord 機器人的功能?(不和諧.py))
                  message.channel.id Discord PY(message.channel.id Discord PY)
                  How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 機器人?)
                  discord.py - Automaticaly Change an Role Color(discord.py - 自動更改角色顏色)
                      <tbody id='ocDGi'></tbody>

                    1. <legend id='ocDGi'><style id='ocDGi'><dir id='ocDGi'><q id='ocDGi'></q></dir></style></legend>
                      1. <small id='ocDGi'></small><noframes id='ocDGi'>

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

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

                            <tfoot id='ocDGi'></tfoot>
                            主站蜘蛛池模板: 亚洲精品第一 | 亚洲性视频 | 色在线看 | 蜜桃精品视频在线 | 99久热| 午夜男人的天堂 | 久久丝袜 | 中文一区 | 欧美极品一区二区 | 五月天国产视频 | 色婷婷在线视频 | 欧美一级淫片007 | caoporon| 日韩在线观看网站 | 久久精品欧美一区二区三区不卡 | 精品久久影院 | 99精品视频免费在线观看 | 91精品国产91久久综合桃花 | 国产高清美女一级a毛片久久w | 精品久久久久久久 | 久久久久国产一区二区三区 | 亚洲精品大全 | 亚洲国产情侣自拍 | 欧美国产精品一区二区三区 | 麻豆一区二区三区精品视频 | 日日操天天射 | 亚洲毛片一区二区 | 国产中文字幕网 | 日日夜夜精品 | 国产精品国产精品国产专区不卡 | 天天干天天想 | 中文字幕亚洲国产 | 一区二区免费在线视频 | 欧美日韩不卡 | h视频在线免费 | 在线看片国产 | 九色av| 国产成人免费 | 国产精品一区二区久久 | 97狠狠干| 亚洲精品一 |