首页 > 解决方案 > kivy中的网格布局格式

问题描述

我目前正在 kivy 开发一个应用程序。我对网格布局和按钮有疑问。这就是我的按钮和图片现在的样子https://i.stack.imgur.com/JrbkL.png。当你看到图片时,你会看到一个播放按钮,在播放按钮旁边我想再添加两张图片。谁能帮忙

这是我的图片代码

GridLayout:
        rows: 3
        size_hint: 1, 1
        pos_hint: {"top": 1, "right": 1}
        Button:
            size_hint: 1, .4
            pos_hint: {"top": .4, "right": 1}
            text: "This is player 1"
        ImageButton:
            size_hint: 1, .2
            pos_hint: {"top": .2, "right": 1}
            source: "play.png"
        Button:
            size_hint: 1, .4
            pos_hint: {"top": .4, "right": 1}
            text: "This the second player"

标签: pythonbuttonkivy

解决方案


您可以尝试在第二行插入另一个 3 列的 GridLayout,如下所示:

GridLayout:
        rows: 3
        size_hint: 1, 1
        pos_hint: {"top": 1, "right": 1}
        Button:
            size_hint: 1, .4
            pos_hint: {"top": .4, "right": 1}
            text: "This is player 1"

        GridLayout:
            cols: 3

            ImageButton:
                size_hint: 1, .2
                pos_hint: {"top": .2, "right": 1}
                source: "play.png"
            ImageButton:
                size_hint: 1, .2
                pos_hint: {"top": .2, "right": 1}
                source: "play.png"
            ImageButton:
                size_hint: 1, .2
                pos_hint: {"top": .2, "right": 1}
                source: "play.png"

        Button:
            size_hint: 1, .4
            pos_hint: {"top": .4, "right": 1}
            text: "This the second player"

推荐阅读