Ошибка: Invalid data after declaration

Phonik

Новичок
Пользователь
Июн 16, 2022
5
0
1
Делал, меню для входа на киви используя kv файл, выдаёт ошибку

Пайтон код:
Python:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.screenmanager import ScreenManager, Screen

from kivy.properties import ObjectProperty


from kivy.config import Config
from kivy.core.window import Window

Window.size = (500, 400)
Window.clearcolor = (43 / 255, 43 / 255, 43 / 255)
Window.title = "Конвентер"

Config.set('graphics', 'resizeable', '0')


class Container(BoxLayout):

    Verification_Login = False
    Verification_Password = False

    Login_Input = ObjectProperty()
    Password_Input = ObjectProperty()

    def Logining(self):
        if self.Login_Input.text == "admin":
            self.Verification_Login = True
            if self.Password_Input.text == "admin":
                self.Verification_Password = True
                if self.Verification_Login and self.Verification_Password:
                    print("asd")
                else:
                    print("c")
            else:
                print("b")
        else:
            print("a")


class MyApp(App):

    # def __init__(self):
    #     super().__init__()

    def build(self):
        return Container()


if __name__ == "__main__":
    MyApp().run()

Файл my.kv:
Python:
<Container>
            Login_Input: login
            Password_Input: password

    AnchorLayout:
        anchor_x: "center"
        anchor_y: "center"

        BoxLayout:
            orientation: "vertical"
            spacing: 1
            size_hint: 0.6, 0.5

            Label:
                text: "Авторизация"
                font_size: "43sp"

            TextInput:
                hint_text: "Логин"
                size_hint: 1, 0.6
                id: login

            TextInput:
                hint_text: "Пароль"
                size_hint: 1, 0.6
                id: password

            Button:
                text: "Войти"
                size_hint: 1, 0.6
                on_press: root.Logining()

Ошибка:
Traceback (most recent call last):
File "/home/phonik/PycharmProjects/MyGimnazia/main.py", line 52, in <module>
MyApp().run()
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/app.py", line 954, in run
self._run_prepare()
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/app.py", line 923, in _run_prepare
self.load_kv(filename=self.kv_file)
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/app.py", line 696, in load_kv
root = Builder.load_file(rfilename)
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/lang/builder.py", line 305, in load_file
return self.load_string(data, **kwargs)
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/lang/builder.py", line 372, in load_string
parser = Parser(content=string, filename=fn)
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/lang/parser.py", line 483, in __init__
self.parse(content)
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/lang/parser.py", line 593, in parse
objects, remaining_lines = self.parse_level(0, lines)
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/lang/parser.py", line 696, in parse_level
_objects, _lines = self.parse_level(
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/lang/parser.py", line 666, in parse_level
raise ParserException(self, ln,
kivy.lang.parser.ParserException: Parser: File "/home/phonik/PycharmProjects/MyGimnazia/my.kv", line 2:
...
1:<Container>
>> 2: Login_Input: login
3: Password_Input: password
4:
...
Invalid data after declaration
 

regnor

Модератор
Команда форума
Модератор
Июл 7, 2020
2 650
472
83
я не специалист в киви, да и вообще не знаю, зачем он вам нужен, но вот так можно

питон код
Python:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.screenmanager import ScreenManager, Screen

from kivy.properties import ObjectProperty


from kivy.config import Config
from kivy.core.window import Window

Window.size = (500, 400)
Window.clearcolor = (43 / 255, 43 / 255, 43 / 255)
Window.title = "Конвентер"

Config.set('graphics', 'resizeable', '0')


class Container(BoxLayout):
    Verification_Login = False
    Verification_Password = False

    def Logining(self, login, password):
        if login == "admin":
            self.Verification_Login = True
            if password == "admin":
                self.Verification_Password = True
                if self.Verification_Login and self.Verification_Password:
                    print("asd")
                else:
                    print("c")
            else:
                print("b")
        else:
            print("a")


class MyApp(App):

    # def __init__(self):
    #     super().__init__()

    def build(self):
        return Container()


if __name__ == "__main__":
    MyApp().run()

my.kv
Python:
<Container>

    AnchorLayout:
        anchor_x: "center"
        anchor_y: "center"

        BoxLayout:
            orientation: "vertical"
            spacing: 1
            size_hint: 0.6, 0.5

            Label:
                text: "Авторизация"
                font_size: "43sp"

            TextInput:
                id: login
                hint_text: "Логин"
                size_hint: 1, 0.6
                id: login

            TextInput:
                id: password
                hint_text: "Пароль"
                size_hint: 1, 0.6
                id: password

            Button:
                text: "Войти"
                size_hint: 1, 0.6
                on_press: root.Logining(login.text, password.text)
 
  • Мне нравится
Реакции: Phonik

Phonik

Новичок
Пользователь
Июн 16, 2022
5
0
1
я не специалист в киви, да и вообще не знаю, зачем он вам нужен, но вот так можно

питон код
Python:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.screenmanager import ScreenManager, Screen

from kivy.properties import ObjectProperty


from kivy.config import Config
from kivy.core.window import Window

Window.size = (500, 400)
Window.clearcolor = (43 / 255, 43 / 255, 43 / 255)
Window.title = "Конвентер"

Config.set('graphics', 'resizeable', '0')


class Container(BoxLayout):
    Verification_Login = False
    Verification_Password = False

    def Logining(self, login, password):
        if login == "admin":
            self.Verification_Login = True
            if password == "admin":
                self.Verification_Password = True
                if self.Verification_Login and self.Verification_Password:
                    print("asd")
                else:
                    print("c")
            else:
                print("b")
        else:
            print("a")


class MyApp(App):

    # def __init__(self):
    #     super().__init__()

    def build(self):
        return Container()


if __name__ == "__main__":
    MyApp().run()

my.kv
Python:
<Container>

    AnchorLayout:
        anchor_x: "center"
        anchor_y: "center"

        BoxLayout:
            orientation: "vertical"
            spacing: 1
            size_hint: 0.6, 0.5

            Label:
                text: "Авторизация"
                font_size: "43sp"

            TextInput:
                id: login
                hint_text: "Логин"
                size_hint: 1, 0.6
                id: login

            TextInput:
                id: password
                hint_text: "Пароль"
                size_hint: 1, 0.6
                id: password

            Button:
                text: "Войти"
                size_hint: 1, 0.6
                on_press: root.Logining(login.text, password.text)
Ошибка
File "/home/phonik/PycharmProjects/MyGimnazia/main.py", line 52, in <module>
MyApp().run()
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/app.py", line 955, in run
runTouchApp()
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/base.py", line 574, in runTouchApp
EventLoop.mainloop()
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/base.py", line 339, in mainloop
self.idle()
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/base.py", line 383, in idle
self.dispatch_input()
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/base.py", line 334, in dispatch_input
post_dispatch_input(*pop(0))
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/base.py", line 263, in post_dispatch_input
listener.dispatch('on_motion', etype, me)
File "kivy/_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/core/window/__init__.py", line 1660, in on_motion
self.dispatch('on_touch_down', me)
File "kivy/_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/core/window/__init__.py", line 1677, in on_touch_down
if w.dispatch('on_touch_down', touch):
File "kivy/_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/uix/widget.py", line 589, in on_touch_down
if child.dispatch('on_touch_down', touch):
File "kivy/_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/uix/widget.py", line 589, in on_touch_down
if child.dispatch('on_touch_down', touch):
File "kivy/_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/uix/widget.py", line 589, in on_touch_down
if child.dispatch('on_touch_down', touch):
File "kivy/_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/uix/behaviors/button.py", line 151, in on_touch_down
self.dispatch('on_press')
File "kivy/_event.pyx", line 727, in kivy._event.EventDispatcher.dispatch
File "kivy/_event.pyx", line 1307, in kivy._event.EventObservers.dispatch
File "kivy/_event.pyx", line 1191, in kivy._event.EventObservers._dispatch
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/lang/builder.py", line 55, in custom_callback
exec(__kvlang__.co_value, idmap)
File "/home/phonik/PycharmProjects/MyGimnazia/my.kv", line 33, in <module>
on_press: root.Logining(login.text, password.text)
TypeError: Logining() takes 1 positional argument but 3 were given
 

regnor

Модератор
Команда форума
Модератор
Июл 7, 2020
2 650
472
83
Ошибка
File "/home/phonik/PycharmProjects/MyGimnazia/main.py", line 52, in <module>
MyApp().run()
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/app.py", line 955, in run
runTouchApp()
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/base.py", line 574, in runTouchApp
EventLoop.mainloop()
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/base.py", line 339, in mainloop
self.idle()
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/base.py", line 383, in idle
self.dispatch_input()
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/base.py", line 334, in dispatch_input
post_dispatch_input(*pop(0))
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/base.py", line 263, in post_dispatch_input
listener.dispatch('on_motion', etype, me)
File "kivy/_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/core/window/__init__.py", line 1660, in on_motion
self.dispatch('on_touch_down', me)
File "kivy/_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/core/window/__init__.py", line 1677, in on_touch_down
if w.dispatch('on_touch_down', touch):
File "kivy/_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/uix/widget.py", line 589, in on_touch_down
if child.dispatch('on_touch_down', touch):
File "kivy/_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/uix/widget.py", line 589, in on_touch_down
if child.dispatch('on_touch_down', touch):
File "kivy/_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/uix/widget.py", line 589, in on_touch_down
if child.dispatch('on_touch_down', touch):
File "kivy/_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/uix/behaviors/button.py", line 151, in on_touch_down
self.dispatch('on_press')
File "kivy/_event.pyx", line 727, in kivy._event.EventDispatcher.dispatch
File "kivy/_event.pyx", line 1307, in kivy._event.EventObservers.dispatch
File "kivy/_event.pyx", line 1191, in kivy._event.EventObservers._dispatch
File "/home/phonik/PycharmProjects/MyGimnazia/venv/lib/python3.8/site-packages/kivy/lang/builder.py", line 55, in custom_callback
exec(__kvlang__.co_value, idmap)
File "/home/phonik/PycharmProjects/MyGimnazia/my.kv", line 33, in <module>
on_press: root.Logining(login.text, password.text)
TypeError: Logining() takes 1 positional argument but 3 were given
вы точно запустили мой код?
покажите что запускаете?
питон код тоже изменился...
 

Форум IT Специалистов