【问题标题】:How to change game kivy background with picture如何用图片更改游戏kivy背景
【发布时间】:2019-01-08 14:03:12
【问题描述】:

我正在尝试更改游戏菜单的背景。但我似乎找不到使用 kivy 插件的方法。

这是我的 .kv 文件。

ScreenManagement :
    transition : FadeTransition()
    MainMenu :
    ThemeMenu :


<MainMenu> :
    name : 'main'

    Label :
        size_hint : 1 , 1

    Rectangle:
           pos: self.pos
           size: self.size
           source: 'Background.jpeg'


    Button :
        id : 'Play'
        background_normal : 'Play button.png'
        background_down : 'Play Button - Press.png'
        size_hint : 0.3 , 0.85
        pos_hint : {'x' : 0.04 , 'y' : 0.03}
        on_release : app.clickfx()

    Button :
        background_normal : 'Theme button.png'
        background_down : 'Themes button - Press.png'
        size_hint : 0.6 , 0.42
        pos_hint : {'x' : 0.35 , 'y' : 0.46}
        on_release : app.root.current = 'theme'
        on_release : app.clickfx()

    Button :
        background_normal : 'Setting button.png'
        background_down :  'Settings button - Press.png'
        size_hint : 0.295 , 0.42
        pos_hint : {'x' : 0.35 , 'y' : 0.03}
        on_release : app.clickfx()

    Button :
        background_normal : 'About button.png'
        background_down : 'Abouts button - Press.png'
        size_hint : 0.295 , 0.42
        pos_hint : {'x' : 0.655 , 'y' : 0.03}
        on_release : app.clickfx()

    Image :
        source : 'Header.png'
        size_hint : 1.2 , 1
        pos_hint : {'x' : -0.1, 'y' : 0.51}

    Image :
        source : 'Pong X.png'
        size_hint : 0.1 , 0.1
        pos_hint : {'x' : 0.005 , 'y' : 0.92 }


<ThemeMenu> :
    name : 'theme'

感谢任何帮助:D

【问题讨论】:

标签: python kivy


【解决方案1】:

解决方案

要更改屏幕背景,在 kv 文件中,使用 canvas.before:Rectangle:source:。详情请参考下面的sn-ps。

设置背景图片

<MainMenu> :
    name : 'main'

    canvas.before:
        Rectangle:
            pos: self.pos
            size: self.size
            source: 'pokemon.jpeg'  # 'Background.jpeg'

屏幕管理器

&lt;MainMenu&gt;: 中,将app.root.current 替换为root.manager.current

Screen's default property manager

默认情况下,每个屏幕都有一个属性管理器,可为您提供 使用的 ScreenManager 的实例。

输出

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-18
    • 2021-11-18
    • 1970-01-01
    • 1970-01-01
    • 2014-12-16
    • 2020-07-27
    • 1970-01-01
    相关资源
    最近更新 更多