【问题标题】:How to put buttons next to eachother in kivy如何在kivy中将按钮放在彼此旁边
【发布时间】:2020-03-15 12:38:05
【问题描述】:

我想像这样将我的按钮 4 个按钮并排放置。https://i.stack.imgur.com/fGIFP.png 但我有这样的按钮https://i.stack.imgur.com/yts0z.png 如何更改它。这是我的代码。你好,现在我添加了更多代码,如果你想将它与其他盒子结合起来怎么办。 现在我有 2 个组合箱。我有问题,他们每个人都会得到 4 个选项

ScrollView:
      GridLayout:
         rows: 3
         id :topic_grid
         size_hint_y: None
         spacing: 40,70
         height: self.minimum_height
         row_default_height: "3500dp"
         row_force_default: True
         BoxLayout:
            orientation: "vertical"
            # question 1
            Label:
               color: 1,0,0,1
               pos_hint:{"top": 1,"left": 1}
               size_hint:1,1
               text: "Which team won the most titles in the SuperLig"
               font_size: 30
            Button:
               pos_hint:{"top": 1,"left": 1}
               size_hint:1,1
               text: "Galatasary"
               size: 30,30
               border: (2, 2, 2, 2)

            Button:
               pos_hint:{"top": 1,"left": 1}
               size_hint:1,1
               text: "Fenerbahce"
               size: 30,30

            Button:
               pos_hint:{"top": 1,"left": 1}
               size_hint:1,1
               text: "Trabzonspor"
               size: 30,30

            Button:
               pos_hint:{"top": 1,"left": 1}
               size_hint:1,1
               text: "Besiktas"
               size: 30,30
            Label:
               color: 1,0,0,1
               pos_hint:{"top": 1,"left": 1}
               size_hint:1,1
               text: "Which team won the 1994 football world cup"
               font_size: 30
            Button:
               pos_hint:{"top": 1,"left": 1}
               size_hint:1,1
               text: "Republic of Ireland"
               size: 30,30
               on_release:
                  self.background_color = 1, 0, 0, 1
            Button:
               pos_hint:{"top": 1,"left": 1}
               size_hint:1,1
               text: "Brazil"
               size: 30,30
               on_release:
                  self.background_color = 250,255,0,0.3
            Button:
               pos_hint:{"top": 1,"left": 1}
               size_hint:1,1
               text: "Germany"
               size: 30,30
               on_release:
                  self.background_color = 1, 0, 0, 1
            Button:
               pos_hint:{"top": 1,"left": 1}
               size_hint:1,1
               text: "USA"
               size: 30,30
               on_release:
                  self.background_color = 1, 0, 0, 1   

【问题讨论】:

    标签: python button formatting kivy kivy-language


    【解决方案1】:

    您可以使用多个BoxLayouts。
    他们每个人都可以有任意数量的孩子(Buttons 或其他BoxLayouts)。

    ScrollView:
          GridLayout:
             rows: 3
             id :topic_grid
             size_hint_y: None
             spacing: 40,70
             height: self.minimum_height
             row_default_height: "3500dp"
             row_force_default: True
             BoxLayout:
                orientation: "vertical"
                # question 1
                # Label:
                #    color: 1,0,0,1
                #    pos_hint:{"top": 1,"left": 1}
                #    size_hint:1,1
                #    text: "Which team won the most titles in the SuperLig"
                #    font_size: 30
                 BoxLayout:
                    Button:
                       pos_hint:{"top": 1,"left": 1}
                       size_hint:1,1
                       text: "Galatasary"
                       size: 30,30
                       border: (2, 2, 2, 2)
    
                    Button:
                       pos_hint:{"top": 1,"left": 1}
                       size_hint:1,1
                       text: "Fenerbahce"
                       size: 30,30
    
                 BoxLayout:
                    Button:
                       pos_hint:{"top": 1,"left": 1}
                       size_hint:1,1
                       text: "Trabzonspor"
                       size: 30,30
    
                    Button:
                       pos_hint:{"top": 1,"left": 1}
                       size_hint:1,1
                       text: "Besiktas"
                       size: 30,30
    

    【讨论】:

    • 你好,如果我想把它和其他盒子结合起来怎么办。
    • 我添加了一些代码,你能帮我检查一下吗,我想把它和更多的盒子结合起来
    • 将每个部分放在自己的BoxLayout 中。除此之外,您必须更具体...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-09
    • 1970-01-01
    相关资源
    最近更新 更多