Kivy屏幕管理器在KV fi中声明后数据无效

2024-07-02 11:34:29 发布

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

在kv文件的第34行声明错误后,我得到了一个无效的数据。在

'Invalid data after declaration')
ParserException: Parser: File "main.kv", line 34:  ...
   32: on_release: app.root.current = "newGame"
   33: MenuButton:
   34: text: "Load Game"
   35: on_release: app.root.current = "loadGame"
   36: MenuButton:  ...  Invalid data after declaration

我认为这个问题与屏幕管理器的实现有关。我最初是用纯python编写的,效果很好。
我用kv语言重写了主屏幕,同样,它也如预期的那样工作。我把子菜单屏幕转换成vk语言,现在我得到一个错误。有什么想法吗?
这是Python:

^{pr2}$

这是ky文件:

#:import FadeTransition kivy.uix.screenmanager

<MenuButton>:
    on_press: app.menuButtonPressed()
    size_hint_y: .125
    background_normal: "images/button.png"
    background_down: "images/buttonPressed.png"

<MenuLayout>:
    orientation: "vertical"

<Layout>:
    orientation: "vertical"
    Image:
        source: "images/banner.png"

<ScreenManagement>:
    transition: FadeTransition()
    MainMenuScreen:
    NewGameMenuScreen:
    LoadGameMenuScreen:
    TutorialMenuScreen:
    SettingsMenuScreen:


<MainMenuScreen>:
    name: "main"
    Layout:
        MenuLayout:
            MenuButton:
                text: "New Game"
                on_release: app.root.current = "newGame"
                MenuButton:
                text: "Load Game"
                on_release: app.root.current = "loadGame"
                MenuButton:
                text: "Tutorial"
                on_release: app.root.current = "tutorial"
                MenuButton:
                text: "Settings"
                on_release: app.root.current = "settings"

<NewGameMenuScreen>:
    name: "newGame"
    Layout:
        MenuLayout:
            MenuButton:
                text: "Conquest Human VS Human"
                MenuButton:
                text: "Choas Human VS Human"
                MenuButton:
                text: "Conquest Human VS CPU"
                MenuButton:
                text: "Choas Human VS Human"

<LoadGameMenuScreen>:
    name: "loadGame"
    Layout:
        MenuLayout:
            MenuButton:
                text: "Conquest Human VS Human"
                MenuButton:
                text: "Choas Human VS Human"
                MenuButton:
                text: "Conquest Human VS CPU"
                MenuButton:
                text: "Choas Human VS Human"

<TutorialMenuScreen>:
    name: "tutorial"
    MenuLayout:
        MenuButton:
                text: "Conquest Mode"
            MenuButton:
                text: "Choas Mode"

<SettingsMenuScreen>:
    name: "settings"
    Layout:
        MenuLayout:
            MenuButton:
                text: "Music"
                MenuButton:
                text: "Sound Effects"
                MenuButton:
                text: "Vibration"
                MenuButton:
                text: "Choas Human VS Human"

Tags: textnameappreleaseonrootcurrentvs