在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"发布于 2016-01-25 13:13:50
在MenuButton:规则中,底部的两行MainMenuScreen缩进了四个空格。
https://stackoverflow.com/questions/34993508
复制相似问题