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

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

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

        <tfoot id='MsnO6'></tfoot>

        如何在 kv 语言中动态制作很多按钮?

        时间:2023-10-10

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

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

            <tfoot id='dioOS'></tfoot>

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

                  <bdo id='dioOS'></bdo><ul id='dioOS'></ul>
                    <tbody id='dioOS'></tbody>
                • 本文介绍了如何在 kv 语言中动态制作很多按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想用 kv 语言制作很多动态按钮.但是现在我不能......我现在将在此下显示源代码.

                  I want to make a lot of Buttons at dynamic in kv language. But now I cannot...... I will show now source under this.

                  BoxLayout:
                      orientation: 'vertical'
                      pos: root.pos
                      size: root.size
                  
                      GridLayout:
                          rows: 2
                          spacing: 5
                          padding: 5
                  
                          Button:
                              text: "X0"
                              on_press: root.X(0)
                          Button:
                              text: "X1"
                              on_press: root.X(1)
                  

                  我想在code下做like

                  I want to make like under code

                  BoxLayout:
                      orientation: 'vertical'
                      pos: root.pos
                      size: root.size
                  
                      GridLayout:
                          rows: 2
                          spacing:5
                          padding:5
                  
                          for i
                              Button:
                                  text: "X#{i}"
                                  on_press: root.X(i)
                  

                  我该怎么办?

                  推荐答案

                  这样的循环在 kv 语言中是不可能的,除了做一些肮脏的 hack.

                  Such loops aren't possible in kv language, other than doing some dirty hacks.

                  要动态创建一组按钮,请使用 ListView 或将它们添加到 py 文件中的循环中.

                  To create a set of buttons dynamically, either use ListView or add them in a loop inside a py file.

                  例子:

                  from functools import partial
                  
                  class MyGrid(GridLayout):
                      def __init__(self, **kwargs):
                          super(MyGrid, self).__init__(**kwargs)
                          self.add_buttons()
                  
                      def add_buttons(self):
                          for i in xrange(5):
                              button = Button(
                                  text='X' + str(i),
                                  on_press=partial(self.X, number=i)
                              )
                              self.add_widget(button)
                  
                      def X(self, caller, number):
                          print  caller, number
                  

                  这篇关于如何在 kv 语言中动态制作很多按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 Kivy 中隐藏 ActionButton? 下一篇:kivy .kv 文件无法读取

                  相关文章

                  最新文章

                  <tfoot id='nkBBO'></tfoot>

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

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

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

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