How can I make a lot of buttons at dynamic in kv language?

前端 未结 3 1820
终归单人心
终归单人心 2020-12-07 03:03

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: \'vert         


        
3条回答
  •  我在风中等你
    2020-12-07 03:22

    This is false, you can easily integrate a loop in your KV file , like this :

        GridLayout:
        pos: root.pos
        size: root.size
        cols:30
        rows:3
        on_parent:
            for i in range(10): strId = "B{0}".format(i+1); i=Button(text=strId, id=strId, on_press=lambda BingoMain:root.my_Function(strId)); self.add_widget(i);
    

提交回复
热议问题