Invalid data after declaration

13 views
Skip to first unread message

Nikolai Atanasov

unread,
May 28, 2024, 3:26:18 PMMay 28
to Kivy users support
Hello,

could you help me with this error in kivy:

#ERROR:
 kivy.lang.parser.ParserException: Parser: File "E:\Projects\Python project\Student_Book\main.kv", line 1:
 ...
 >>    1:Number_of_student: Number_of_Student
       2:Name: Name
       3:Surname: Surname
 ...
 Invalid data after declaration

#MAIN CODE:

import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty


class MyGrid(GridLayout):
Number_of_student = ObjectProperty(None)
Name = ObjectProperty(None)
Surname = ObjectProperty(None)
Family_Name = ObjectProperty(None)
Age = ObjectProperty(None)
Gender = ObjectProperty(None)
Major = ObjectProperty(None)
Faculty = ObjectProperty(None)
University = ObjectProperty(None)


def pressed(self):
print("Fuck yeah")

# #Variables for the input Data
# Number_of_student = self.Number_of_Student.text
# Name = self.Name.text
# Surname = self.Surname.text
# Family_Name = self.Family_Name.text
# Age = self.Age.text
# Gender = self.Gender.text
# Major = self.Major.text
# Faculty = self.Faculty.text
# University = self.University.text

print("number_of_student: ", self.Number_of_student.text)
print("Name: ", self.Name.text)
print("Surname: ", self.Surname.text)
print("Family_Name: ", self.Family_Name.text)
print("Age: ", self.Age.text)
print("Gender: ", self.Gender.text)
print("Major: ", self.Major.text)
print("Faculty: ", self.Faculty.text)
print("University: ", self.University.text)

#Clear the input fields
self.Number_of_Student.text = ""
self.Name.text = ""
self.Surname.text = ""
self.Family_Name.text = ""
self.Age.text = ""
self.Gender.text = ""
self.Major.text = ""
self.Faculty.text = ""
self.University.text = ""


class MainApp(App):
def build(self):
return MyGrid()


app = MainApp()
app.run()


#.KV file
<MyGrid>

Number_of_student: Number_of_Student
Name: Name
Surname: Surname
Family_Name: Family_Name
Age: Age
Gender: Gender
Major: Major
Faculty: Faculty
University: University

GridLayout:
cols:1
size: root.width -200, root.height -200
pos: 100, 100

GridLayout:
cols: 2

Label:
text:"Факултетен Номер: "
TextInput:
multiline:False
id: Number_of_Student

Label:
text:"Име: "
TextInput:
multiline:False
id: Name


Label:
text:"Презиме: "
TextInput:
multiline:False
id: Surname


Label:
text:"Фамилия: "
TextInput:
multiline:False
id: Family_Name


Label:
text:"години: "
TextInput:
multiline:False
id: Age


Label:
text:"пол: "
TextInput:
multiline:False
id: Gender


Label:
text:"Специалност: "
TextInput:
multiline:False
id: Major


Label:
text:"Факултет: "
TextInput:
multiline:False
id: Faculty


Label:
text:"Университет: "
TextInput:
multiline:False
id: University

Button:
text:"Submit"
on_press: root.pressed()

ElliotG

unread,
May 28, 2024, 4:10:00 PMMay 28
to Kivy users support
To past code into the website and retain the formatting, right click and select paste as plain text.

ElliotG

unread,
May 28, 2024, 4:34:32 PMMay 28
to Kivy users support
The convention for python variables is lowercase with words separated by underscores as necessary to improve readability.  The convention for classes is CapWords.  See: https://pep8.org/#introduction

Unfortunately there are cases within kv, where the python conventions are expected.  This is one of these cases.  Change your property names to start with lower case letters and things will work as expected.

You code was not properly formatted on the site so I simplified a few things as well as changing the case as required.

import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty


class MyGrid(GridLayout):
    number_of_student = ObjectProperty(None)  # note leading characters as lowercase.
    name = ObjectProperty(None)
    surname = ObjectProperty(None)
    family_Name = ObjectProperty(None)
    age = ObjectProperty(None)
    gender = ObjectProperty(None)
    major = ObjectProperty(None)
    faculty = ObjectProperty(None)
    university = ObjectProperty(None)



    def pressed(self):
        print("Fuck yeah")

        # #Variables for the input Data
        # Number_of_student = self.Number_of_Student.text
        # Name = self.Name.text
        # Surname = self.Surname.text
        # Family_Name = self.Family_Name.text
        # Age = self.Age.text
        # Gender = self.Gender.text
        # Major = self.Major.text
        # Faculty = self.Faculty.text
        # University = self.University.text

        print("number_of_student: ", self.number_of_student.text)
        print("Name: ", self.name.text)
        print("Surname: ", self.surname.text)
        print("Family_Name: ", self.family_Name.text)
        print("Age: ", self.age.text)
        print("Gender: ", self.gender.text)
        print("Major: ", self.major.text)
        print("Faculty: ", self.faculty.text)
        print("University: ", self.university.text)

        #Clear the input fields
        self.number_of_student.text = ""
        self.name.text = ""
        self.surname.text = ""
        self.family_Name.text = ""
        self.age.text = ""
        self.gender.text = ""
        self.major.text = ""
        self.faculty.text = ""
        self.university.text = ""


class MainApp(App):
   pass


app = MainApp()
app.run()

=====================

<MyGrid>:
    number_of_student: Number_of_Student
    name: Name
    surname: Surname
    family_Name: Family_Name
    age: Age
    gender: Gender
    major: Major
    faculty: Faculty
    university: University
MyGrid:
Reply all
Reply to author
Forward
0 new messages