如何将位于同一行的 Kivy 小部件移动得更远?

How to move Kivy widgets that live on the same row further apart?

我想找出一种方法来保留我的 main.kv 文件头设置中的三个小部件,并将两个外部小部件进一步移动到屏幕边缘。这就像一个顶部横幅,显示在每个屏幕上并包含时间、'home button' 和 'settings button'。我有一个 main.kv 布局的绝对狗早餐,我真的不知道如何更改它以使其功能齐全并保持小部件可见。我将包括我正在谈论的部分的框架。

main.kv

GridLayout:
    cols: 1
    FloatLayout:
        GridLayout:
            canvas:
                Color:
                    rgb: utils.get_color_from_hex("#000523")
                Rectangle:
                    size: self.size
                    pos: self.pos
            rows: 1
            pos_hint: {"top": 1, "left": 1}
            size_hint: 1, .07
        GridLayout:
            rows: 1
            canvas:
                Color:
                    rgb: utils.get_color_from_hex("#000523")
                Rectangle:
                    size: self.size
                    pos: self.pos
            pos_hint: {"top": .93, "center_x": .5}
            size_hint: 1, .03
            ImageButton:
                id: home_button
                source: "icons/home.png"
                opacity: 1 if self.state == 'normal' else .5
                on_release:
                    app.change_screen("home_screen")
                    app.clear_results()
            Label:
                id: utc_time
                markup: True
                font_size: '20sp'
                text: ""
            ImageButton:
                id: settings_button
                source: "icons/cog.png"
                opacity: 1 if self.state == 'normal' else .5
                on_release:
                    app.change_screen("settings_screen")

我发现将我的三个小部件放回一个选项卡(不是在 GridLayout 下,而是作为 FloatLayout 的子项)允许我将它们重新定位到更多我想要的位置。但这不起作用,因为我在我的 main.py 中引用它们并参考当前屏幕添加或删除这些小部件。我一直遇到的问题是它一直想在小部件之上添加小部件。我也会包括那个功能。

main.py

def home_setting_widgets(self, screen_name):  # this is going to display the home and setting widgets once the app has already been opened
    home_button = self.root.ids["home_button"]
    utc_time = self.root.ids["utc_time"]
    settings_button = self.root.ids["settings_button"]
    grid_layout = self.root.children[0].children[2]
    if screen_name == "login_screen" or screen_name == "signup_screen" or screen_name == "welcome_screen":
        grid_layout.remove_widget(home_button)  # remove widgets if on the 3 screens listed
        grid_layout.remove_widget(utc_time)
        grid_layout.remove_widget(settings_button)
        self.home_and_setting = False
    else:
        if self.home_and_setting == False:
            grid_layout.add_widget(home_button)  # add widgets
            grid_layout.add_widget(utc_time)
            grid_layout.add_widget(settings_button)
            self.home_and_setting = True

我认为如果我将它们从 GridLayout 中移出,问题在于它们不会作为一个组引用,而是作为单独的小部件引用。我目前将它们捆绑在一起并在 grid_layout = self.root.children[0].children[2] 行中引用。

我尝试从 main.kv 中删除 GridLayout 及其内容,我尝试 'tabbing' 将小部件移至不同位置,我尝试以多种不同方式引用小部件。

我想做的就是将 'home button' 和 'settings button' 稍微分开一点,这让我卡住了。如果有办法在不破坏一切的情况下移动它们,请告诉我。非常感谢您的帮助,谢谢。

尝试向具有“主页”、“时间”和“设置”的 GridLayout 添加一些间距

GridLayout:
    rows: 1
    spacing: 1000
    canvas:

我无法从 kivy 文档页面获取要上传的图像,但 GridLayout kivy 文档有您要的“间距”信息。