【问题标题】:how to put buttons above the button in kivy language and python class如何在kivy语言和python类中将按钮放在按钮上方
【发布时间】:2021-06-21 14:36:41
【问题描述】:

我想将这些按钮放在网格布局中的按钮 (2) 上方,就像 (0,1,2) 使用 python 语言一样,并且不会中断我输入的 kivy 语言我的意思是不要在 kivy 中使用 for 循环语言

from kivy.lang.builder import Builder
from kivy.app import App
from kivy.uix.button import Button

kv=Builder.load_string('''
BoxLayout:
    GridLayout:
        id:grid_button
        cols:1
        Button:
            text:'2'
''')

class Accounting(App):
    def build(self):
        return kv
    def on_start(self):
        for a in range(2):
#I want to put these buttons above the button (2) in grid layout
            self.root.ids.grid_button.add_widget(Button(text=str(a)))

Accounting().run()

【问题讨论】:

    标签: python kivy kivy-language


    【解决方案1】:
    from kivy.lang.builder import Builder
    from kivy.app import App
    from kivy.uix.button import Button
    
    kv=Builder.load_string('''
    BoxLayout:
        GridLayout:
            id:grid_button
            cols:1
            Button:
                text:'2'
    ''')
    
    class Accounting(App):
        def build(self):
            return kv
        def on_start(self):
            for a in range(2):
    #I want to put these buttons above the button (2) in grid layout
                self.root.ids.grid_button.add_widget(Button(text=str(a)), index=1)
    
    Accounting().run()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-21
      相关资源
      最近更新 更多