首页 > 解决方案 > kivy中的静态背景

问题描述

我想知道是否有办法在带有屏幕管理器的 Kivy 应用程序中获取静态背景。对于静态,我的意思是即使在切换屏幕时,背景也会保持原样。我正在使用 .kv 文件进行布局。我猜这与 .kv 文件中的放置顺序有关。

谢谢!

标签: pythonbackgroundkivy

解决方案


您可以使用浮动布局作为每个屏幕中的根小部件,并将图像和屏幕中的其他布局添加到浮动布局中,这是 kv 中的代码示例:

Screen: # Screen 1
    id: Home
    FloatLayout:
        Image:
            source: "path to the image"

        BoxLayout: # Here you put your other layout
            # And here the code you had

Screen: # Screen 2
    id: Another Screen
    FloatLayout:
        Image:
            source: "path to the image"

        BoxLayout: # Here you put your other layout
            # And here the code you had

这是我知道的解决方案,它可能不适合您,但我会将其他选择留给其他人......


推荐阅读