'Invalid data after declaration in Kivy

I don't understand why I have this type of error when I run my code. I've checked this several times and everything seems to be good, still the code does not want to run.

Here's my __main__.py file :

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.properties import ObjectProperty  # at top of file

class AccountDetailsForm(AnchorLayout):

    server_box = ObjectProperty()
    username_box = ObjectProperty()
    password_box = ObjectProperty()

    def login(self):
        print(self.server_box.text)
        print(self.username_box.text)
        print(self.password_box.text)


class Orkiv(App):
    pass

Orkiv().run()

And here's my orkiv.kv file :

AccountDetailsForm:

<AccountDetailsForm>:
    anchor_y: "top"
    server_box: server_input
    username_box: username_input
    password_box: password_input

    BoxLayout:
        orientation: "vertical"
        height: "200dp"
        size_hint_y: None

        GridLayout:
            cols: 2
            row_default_height: "40dp"
            row_force_default: True
            spacing: "10dp"
            padding: "10dp"
        Label:
            text: "Server" //THE ERROR SEEMS TO HAPPEN HERE
        AccountDetailsTextInput:
            id: server_input
        Label:
            text: "Username"
        AccountDetailsTextInput:
            id: username_input
        Label:
            text: "Password"
        AccountDetailsTextInput:
            password: True
            id: password_input

    Button:
        size_hint_y: None
        height: "40dp"
        text: "Login"
        on_press: root.login()

Any ideas ? Thanks.



Solution 1:[1]

In your orkiv.kv file, change AccountDetailsTextInput to just TextInput.

AccountDetailsForm:

<AccountDetailsForm>:

    anchor_y: "top"
    server_box: server_input
    username_box: username_input
    password_box: password_input

    BoxLayout:

        orientation: "vertical"
        height: "200dp"
        size_hint_y: None

        GridLayout:
            cols: 2
            row_default_height: "40dp"
            row_force_default: True
            spacing: "10dp"
            padding: "10dp"

        Label:
            text: "Server"

        TextInput:
            id: server_input

        Label:
            text: "Username"

        TextInput:
            id: username_input

        Label:
            text: "Password"

        TextInput:
            password: True
            id: password_input

    Button:

        size_hint_y: None
        height: "40dp"
        text: "Login"
        on_press: root.login()

The app should run. See my output below.

enter image description here

Let us know if this helps.

Solution 2:[2]

According to kivy module documentation, if you want to provide a box for editable plain text use the class "TextInput". There is no class by the name "AccountDetailsTextInput".

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 WitchGod
Solution 2 Md Ibrahim Ayaz