声明后的数据无效

时间:2018-02-25 08:02:57

标签: python python-3.x runtime-error kivy

我正在尝试制作一种个人词汇日记,我是python和kivy的新手。我的代码给出了一个错误,我已经多次检查但仍然没有工作。它说声明后的无效数据我检查了任何可能的错误(我知道)。我将不胜感激任何帮助 这是我的代码 -

import kivy
kivy.require('1.10.0')

from kivy.uix.stacklayout import StackLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label 
from kivy.app import App 
from kivy.uix.popup import Popup   
from kivy.uix.screenmanager import ScreenManager, Screen 
from kivy.lang import Builder 
from kivy.properties import ObjectProperty

import json

Builder.load_file('VocabularyJournal.kv')

class MenuPage(Screen, StackLayout):
    pass

class WordInsertPage(Screen,FloatLayout):
    pass

class NewWordPage(Screen,StackLayout):
    word_box = ObjectProperty()
    meaning_box = ObjectProperty()
    Synonym_box = ObjectProperty()
    Ant_box = ObjectProperty()
    sentence_box = ObjectProperty()
    def input_data(self):
        data={}

        m=self.word_box.text
        data[m]={}
        data[m]['meaning']=self.meaning_box.text
        data[m]['synonym']=self.Synonym_box.text
        data[m]['antonym']=self.Ant_box.text
        data[m]['sentence']=self.sentence_box.text

    def saving_data(self):
        with open('vocab_new_word_page.txt','w') as of:
        json.dump(data,of)


class FlashCard(Screen):
    pass

class WordGroups(Screen):
    pass

sm=ScreenManager()
sm.add_widget(MenuPage(name='menu'))
sm.add_widget(WordInsertPage(name='insertword'))
sm.add_widget(NewWordPage(name='newword')) 
sm.add_widget(FlashCard(name='flashcard'))
sm.add_widget(WordGroups(name='wordgroup'))

class VocabularyJournalApp(App):
    def build(self):
    return sm

object = VocabularyJournalApp()
object.run()

这是kv文件 -

<MenuPage>:
     Label: 
         text: "Vocabulary Journal"
         size_hint: .90,.10

     StackLayout:
         orientation: 'tb-rl'
         spacing: 10
         padding: 10

         Button:
             text: 'Search'
             size_hint: None,.20
             width: 130
             background_down:'darkgrey.png'
             on_press: root.manager.current='insertword'
         Button:
             text: 'New Word'
             size_hint: None,.20
             width: 130
             background_down:'darkgrey.png'
             on_press: root.manager.current='insertword'
         Button:
             text: 'Flash Cards'
             size_hint: None,.20
             width: 130
             background_down:'darkgrey.png'
             on_press: root.manager.current='flashcard'

         Button:
             text: 'Word Groups'
             size_hint: None,.20
             width: 130
             background_down:'darkgrey.png'
             on_press: root.manager.current='wordgroup'

<WordInsertPage>:
    FloatLayout:

        Button: 
            text: "New Word"
            on_press: root.manager.current='newword'
            font_size: 30
            color: 1,0,1,1
            size_hint: .3, .1
            pos_hint: {"center_x": .5, "center_y": 0.5}
            background_down: 'darkgrey.png'
<NewWordPage>:
    id: refer_to_it
    StackLayout:
        orientation: 'tb-rl'
        spacing: 10
        word_box: word_input
        meaning_box: meaning_input
        Synonym_box: Synonym_input
        Ant_box: ant_input
        sentence_box: sentence_input
        padding: 90
        TextInput:
            text: "write your word here"
            color: 1,1,1,1
            id: word_input
            width: 300
            size_hint: None, .10

        TextInput:
            text: "write meaning of your word here"
            color: 1,1,1,1
            id: meaning_input
            width: 600
            size_hint: None, .20

        TextInput:
            text: "write Synonyms of your word here"
            color: 1,1,1,1
            id: Synonym_input
            width: 600
            size_hint: None, .20

        TextInput:
            text: "write antonyms of your text here"
            color: 1,1,1,1
            id: ant_input
            width: 600
            size_hint: None, .20

        TextInput:
            text: "write a sentence based on your word here"
            color: 1,1,1,1
            id: sentence_input
            width: 600
            size_hint: None, .20

        Button:
            text: 'Save'
            size_hint: None,.10
            width: 130
            background_down:'darkgrey.png'
            on_press: refer_to_it.saving_data   

这是错误 -

    [INFO   ] [Logger      ] Record log in C:\Users\HP\.kivy\logs\kivy_18-
    02-25_5.txt
    [INFO   ] [Kivy        ] v1.10.0 
    [INFO   ] [Python      ] v3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) 
    [MSC v.1900 32 bit (Intel)]
    [INFO   ] [Factory     ] 194 symbols loaded
    [INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_gif 
    (img_pil, img_ffpyplayer ignored)
    [INFO   ] [Text        ] Provider: sdl2
    Traceback (most recent call last):
         File "E:\SharanyaPy\desktop vocabulary journal\vocabJournal.py", 
            line 15, in <module>
             Builder.load_file('VocabularyJournal.kv')
        File "C:\Users\HP\AppData\Local\Programs\Python\Python36-
            32\lib\site-packages\kivy\lang\builder.py", line 301, in 
            load_file
            return self.load_string(data, **kwargs)
        File "C:\Users\HP\AppData\Local\Programs\Python\Python36-
               32\lib\site-packages\kivy\lang\builder.py", line 350, in 
             load_string
              parser = Parser(content=string, filename=fn)
        File "C:\Users\HP\AppData\Local\Programs\Python\Python36-
             32\lib\site-packages\kivy\lang\parser.py", line 392, in 
             __init__
             self.parse(content)
        File "C:\Users\HP\AppData\Local\Programs\Python\Python36-
             32\lib\site-packages\kivy\lang\parser.py", line 501, in parse
                objects, remaining_lines = self.parse_level(0, lines)
        File "C:\Users\HP\AppData\Local\Programs\Python\Python36-
             32\lib\site-packages\kivy\lang\parser.py", line 605, in 
             parse_level
             level + 1, lines[i:], spaces) 
        File "C:\Users\HP\AppData\Local\Programs\Python\Python36-
              32\lib\site-packages\kivy\lang\parser.py", line 605, in 
              parse_level
              level + 1, lines[i:], spaces)
        File "C:\Users\HP\AppData\Local\Programs\Python\Python36-
              32\lib\site-packages\kivy\lang\parser.py", line 575, in 
              parse_level
            'Invalid data after declaration')
            kivy.lang.parser.ParserException: Parser: File 
           "E:\SharanyaPy\desktop vocabulary journal\VocabularyJournal.kv", 
            line 55:
             ...
             53:        word_box: word_input
             54:        meaning_box: meaning_input
        >>   55:        Synonym_box: Synonym_input
             56:        Ant_box: ant_input
             57:        sentence_box: sentence_input
             ...
             Invalid data after declaration

我已经检查了缩进,打错了我所知道的任何其他错误,但它仍然无效。

0 个答案:

没有答案