我的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语言,现在我收到错误。任何想法?
这是蟒蛇:
from kivy.lang import Builder
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.image import Image
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.core.audio import SoundLoader
from plyer import vibrator
presentation = Builder.load_file('main.kv')
backgroundMusic = SoundLoader.load('sounds/intro.mp3')
buttonSound = SoundLoader.load('sounds/button.mp3')
backgroundMusic.play()
class Layout(BoxLayout): pass
class MenuLayout(BoxLayout): pass
class MenuButton(Button): pass
class MainMenuScreen(Screen): pass
class NewGameMenuScreen(Screen): pass
class LoadGameMenuScreen(Screen): pass
class TutorialMenuScreen(Screen): pass
class SettingsMenuScreen(Screen): pass
class ScreenManagement(ScreenManager): pass
class Uranium235App(App):
def menuButtonPressed(event):
buttonSound.play()
try:
vibrator.vibrate(.125)
except NotImplementedError: pass
def build(self):
return presentation
if __name__ == '__main__':
Uranium235App().run()
这是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"
答案 0 :(得分:0)
MenuButton:
规则中有两个MainMenuScreen
行的前两行缩进了四个空格。