Reputation: 391
I am trying to make a sort of personal vocabulary journal, I am new to python and kivy. My code is giving an error, i have checked it several times but still not working.It says invalid data after declaration I have checked for any possible error(which i know). I would appreciate any kind of help.
here is my code-
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()
and here is the kv file-
<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
here is the error -
[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
I have checked the indentation,typos any other mistake that i know of, but it is still not working .
Upvotes: 2
Views: 1103
Reputation: 243955
According to the docs:
Widget names should start with upper case letters while property names should start with lower case ones. Following the PEP8 Naming Conventions is encouraged.
So in your case the solution is to change the first letter of the properties to lowercase:
.py
synonym_box = ObjectProperty()
ant_box = ObjectProperty()
.kv
meaning_box: meaning_input
synonym_box: Synonym_input
Upvotes: 3