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

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

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

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

      2. ScrollView 小部件在 kivy 中不滚动

        时间:2023-10-11
      3. <legend id='9Asbp'><style id='9Asbp'><dir id='9Asbp'><q id='9Asbp'></q></dir></style></legend>
        <i id='9Asbp'><tr id='9Asbp'><dt id='9Asbp'><q id='9Asbp'><span id='9Asbp'><b id='9Asbp'><form id='9Asbp'><ins id='9Asbp'></ins><ul id='9Asbp'></ul><sub id='9Asbp'></sub></form><legend id='9Asbp'></legend><bdo id='9Asbp'><pre id='9Asbp'><center id='9Asbp'></center></pre></bdo></b><th id='9Asbp'></th></span></q></dt></tr></i><div id='9Asbp'><tfoot id='9Asbp'></tfoot><dl id='9Asbp'><fieldset id='9Asbp'></fieldset></dl></div>

          <small id='9Asbp'></small><noframes id='9Asbp'>

              <tbody id='9Asbp'></tbody>

            <tfoot id='9Asbp'></tfoot>
              <bdo id='9Asbp'></bdo><ul id='9Asbp'></ul>
                  本文介绍了ScrollView 小部件在 kivy 中不滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我在尝试使动态生成的标签堆栈可滚动时遇到一些问题.我可能误解了应该使用 ScrollView 的方式,所以我希望有人可以为我澄清一下.下面的代码从一个csv中读取一堆数据,当那个代码显示出来的时候,如果有很多数据,程序基本上会尝试把所有的text/Labels压缩到GridLayout中.我希望数据可以滚动.这是代码的抽象版本:

                  I'm having some issues using the ScollView Widget in an attempt to make a dynamically-generated stack of labels scrollable. It's possible that I'm misunderstanding the way ScrollView should be utilized, so I'm hoping somebody could clarify it for me. The following code reads a bunch of data from a csv, and when that code is displayed, if there is a lot of data, the program will basically try to compress all the text/Labels into the GridLayout. I'd like the data to be scrollable. Here's an abstracted version of the code:

                  class showData(Screen):
                  def __init__(self, **kwargs):
                      super(showData, self).__init__(**kwargs)
                  
                      self.my_data = read_csv_to_dict()
                      self.data_exists = 0 if len(self.my_data) == 0 else 1 
                  
                      ### Create Widgets ###      
                      layout_main = BoxLayout(orientation = 'vertical')
                      layout_back_button = BoxLayout(padding = [0, 0, 0, 20])
                      self.layout_data = GridLayout(cols = 3 if self.data_exists else 1)  
                      self.scrollview_data = ScrollView()
                  
                      button_back = Button(text = 'Main menu')
                  
                      ### Add widgets ###
                      self.add_widget(layout_main)
                      layout_main.add_widget(layout_back_button)
                      layout_main.add_widget(self.scrollview_data)
                  
                      layout_back_button.add_widget(button_back)
                  
                      if self.data_exists:
                          self.layout_data.add_widget(Label(text = 'label 1'))
                          self.layout_data.add_widget(Label(text = 'label 2'))
                          self.layout_data.add_widget(Label(text = 'label 3'))
                          self.display_data(self)
                          self.scrollview_data.add_widget(self.layout_data)
                      else:
                          self.scrollview_data.add_widget(Label(text = 'Records are empty'))
                  
                      ### Create button bindings ###
                      button_back.bind(on_press = switch_screen_to_main)      
                  
                  def display_data(obj, self):
                  
                      data_dictReader = read_csv_to_dictReader()
                  
                      for data_row in data_dictReader:
                          for value in data_row.values():
                              self.layout_data.add_widget( Label( text = value))
                  

                  GridLayout/data 不可滚动.有人可以告诉我如何修复上面的代码以使其可滚动吗?谢谢你.

                  The GridLayout/data is not scrollable. Can someone tell me how to fix the code above to make it scrollable? Thank you.

                  推荐答案

                  你不见了 Kivy 文档中的一些内容 在您的 GridLayout 上.它们是确保 GridLayout 大到可以滚动"的必要条件:

                  You are missing a few things from the Kivy Documentation on your GridLayout. They are necessary to make sure that the GridLayout is "big enough to scroll":

                  1. 您必须确保将 size_hint_y 设置为 None,因为在这种情况下默认的 1 不方便
                  2. GridLayoutminimum_height绑定到layout.setter('height').
                  3. 确保 ScrollView 具有适合滚动的大小
                  1. You got to be sure that you set the size_hint_y to None, because the default 1 is not convenient in this case
                  2. Bind the minimum_height of the GridLayout to layout.setter('height').
                  3. Be sure that the ScrollView has the right size to accommodate the scroll

                  这个例子和你在文档中找到的差不多:

                  This example is pretty much what you find in the documentation:

                  from kivy.app import App
                  from kivy.uix.scrollview import ScrollView
                  from kivy.uix.gridlayout import GridLayout
                  from kivy.uix.button import Button
                  
                  class Example(App):
                  
                      def build(self):
                          layout = GridLayout(cols=1, spacing=10, size_hint_y=None)
                          # Make sure the height is such that there is something to scroll.
                          layout.bind(minimum_height=layout.setter('height'))
                          for i in range(30):
                              btn = Button(text=str(i), size_hint_y=None, height=40)
                              layout.add_widget(btn)
                          root = ScrollView()
                          root.add_widget(layout)
                          return root
                  
                  if __name__ == '__main__':
                      Example().run()
                  

                  在本例中,ScrollViewWindow 的大小,但您可以使用 size_hintsize 属性.

                  In this example, the ScrollView is the size of the Window but you can manipulate it with the size_hint and size properties.

                  这篇关于ScrollView 小部件在 kivy 中不滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使用 Kivy 制作工具提示? 下一篇:discord.py 中的 Cog 和 Extension 有什么区别?

                  相关文章

                  最新文章

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

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

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