如何用pictu改变游戏kivy的背景

2024-09-29 23:25:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图改变我的游戏菜单的背景。但我似乎找不到一种方法来使用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


Tags: posappsourcesizereleasepngonbutton
1条回答
网友
1楼 · 发布于 2024-09-29 23:25:12

解决方案

要更改屏幕的背景,在kv文件中,使用canvas.before:Rectangle:和{}。有关详细信息,请参阅下面的片段。在

设置背景图像

<MainMenu> :
    name : 'main'

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

屏幕管理器

<MainMenu>:中,将app.root.current替换为root.manager.current

Screen's default property manager

Each screen has by default a property manager that gives you the instance of the ScreenManager used.

输出

Img01 - Background image

相关问题 更多 >

    热门问题