@6APAIII
000000001010100101010

AttributeError: 'super' object has no attribute '__getattr__'?

Код:

from kivy.lang import Builder
from kivy.uix.floatlayout import FloatLayout
from kivymd.uix.tab import MDTabsBase
from kivymd.app import MDApp
KV = '''
Screen:
    MDTabs:
        id: tabs
<Tab1>:
    BoxLayout:
        MDTextField:
            id: vvod
            pos_hint: {'center_x':.5,'center_y':.5}
        MDRaisedButton:
            pos_hint: {'center_x':.1,'center_y':.4}
            on_press: app.func()
'''
class Tab1(MDTabsBase,FloatLayout):
    pass
class Test(MDApp):
    def build(self):
        return Builder.load_string(KV)
    def on_start(self):
        self.root.ids.tabs.add_widget(Tab1(text='Tab1'))
    def func(self):
        print(self.root.ids.vvod.text)
Test().run()

При нажатии на кнопку ошибка:

Traceback (most recent call last):
   File "kivy\properties.pyx", line 861, in kivy.properties.ObservableDict.__getattr__
 KeyError: 'vvod'
 
 During handling of the above exception, another exception occurred:
 
 Traceback (most recent call last):
   File "C:\Users\lolo\PycharmProjects\FindWord\FindWord.py", line 28, in <module>
     Test().run()
   File "C:\Users\lolo\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\app.py", line 950, in run
     runTouchApp()
   File "C:\Users\lolo\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\base.py", line 582, in runTouchApp
     EventLoop.mainloop()
   File "C:\Users\lolo\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\base.py", line 347, in mainloop
     self.idle()
   File "C:\Users\lolo\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\base.py", line 391, in idle
     self.dispatch_input()
   File "C:\Users\lolo\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\base.py", line 342, in dispatch_input
     post_dispatch_input(*pop(0))
   File "C:\Users\lolo\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\base.py", line 248, in post_dispatch_input
     listener.dispatch('on_motion', etype, me)
   File "kivy\_event.pyx", line 709, in kivy._event.EventDispatcher.dispatch
   File "C:\Users\lolo\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\core\window\__init__.py", line 1416, in on_motion
     self.dispatch('on_touch_up', me)
   File "kivy\_event.pyx", line 709, in kivy._event.EventDispatcher.dispatch
   File "C:\Users\lolo\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\core\window\__init__.py", line 1452, in on_touch_up
     if w.dispatch('on_touch_up', touch):
   File "kivy\_event.pyx", line 709, in kivy._event.EventDispatcher.dispatch
   File "C:\Users\lolo\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\uix\relativelayout.py", line 313, in on_touch_up
     ret = super(RelativeLayout, self).on_touch_up(touch)
   File "C:\Users\lolo\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\uix\widget.py", line 567, in on_touch_up
     if child.dispatch('on_touch_up', touch):
   File "kivy\_event.pyx", line 709, in kivy._event.EventDispatcher.dispatch
   File "C:\Users\lolo\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\uix\widget.py", line 567, in on_touch_up
     if child.dispatch('on_touch_up', touch):
   File "kivy\_event.pyx", line 709, in kivy._event.EventDispatcher.dispatch
   File "C:\Users\lolo\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\uix\widget.py", line 567, in on_touch_up
     if child.dispatch('on_touch_up', touch):
   File "kivy\_event.pyx", line 709, in kivy._event.EventDispatcher.dispatch
   File "C:\Users\lolo\AppData\Local\Programs\Python\Python39\lib\site-packages\kivymd\uix\carousel.py", line 93, in on_touch_up
     return super().on_touch_up(touch)
   File "C:\Users\lolo\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\uix\carousel.py", line 610, in on_touch_up
     super(Carousel, self).on_touch_down(touch)
   File "C:\Users\lolo\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\uix\widget.py", line 545, in on_touch_down
     if child.dispatch('on_touch_down', touch):
   File "kivy\_event.pyx", line 709, in kivy._event.EventDispatcher.dispatch
   File "C:\Users\lolo\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\uix\relativelayout.py", line 297, in on_touch_down
     ret = super(RelativeLayout, self).on_touch_down(touch)
   File "C:\Users\lolo\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\uix\widget.py", line 545, in on_touch_down
     if child.dispatch('on_touch_down', touch):
   File "kivy\_event.pyx", line 709, in kivy._event.EventDispatcher.dispatch
   File "C:\Users\lolo\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\uix\widget.py", line 545, in on_touch_down
     if child.dispatch('on_touch_down', touch):
   File "kivy\_event.pyx", line 709, in kivy._event.EventDispatcher.dispatch
   File "C:\Users\lolo\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\uix\widget.py", line 545, in on_touch_down
     if child.dispatch('on_touch_down', touch):
   File "kivy\_event.pyx", line 709, in kivy._event.EventDispatcher.dispatch
   File "C:\Users\lolo\AppData\Local\Programs\Python\Python39\lib\site-packages\kivymd\uix\behaviors\ripplebehavior.py", line 283, in on_touch_down
     return super().on_touch_down(touch)
   File "C:\Users\lolo\AppData\Local\Programs\Python\Python39\lib\site-packages\kivymd\uix\button.py", line 1004, in on_touch_down
     return super().on_touch_down(touch)
   File "C:\Users\lolo\AppData\Local\Programs\Python\Python39\lib\site-packages\kivymd\uix\button.py", line 939, in on_touch_down
     return super().on_touch_down(touch)
   File "C:\Users\lolo\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\uix\behaviors\button.py", line 151, in on_touch_down
     self.dispatch('on_press')
   File "kivy\_event.pyx", line 705, in kivy._event.EventDispatcher.dispatch
   File "kivy\_event.pyx", line 1248, in kivy._event.EventObservers.dispatch
   File "kivy\_event.pyx", line 1132, in kivy._event.EventObservers._dispatch
   File "C:\Users\lolo\AppData\Local\Programs\Python\Python39\lib\site-packages\kivy\lang\builder.py", line 57, in custom_callback
     exec(__kvlang__.co_value, idmap)
   File "<string>", line 12, in <module>
   File "C:\Users\lolo\PycharmProjects\FindWord\FindWord.py", line 27, in func
     print(self.root.ids.vvod.text)
   File "kivy\properties.pyx", line 864, in kivy.properties.ObservableDict.__getattr__
 AttributeError: 'super' object has no attribute '__getattr__'

Без виджета Tabs все работает. Подскажите как исправить ошибку
Мне кажется что ошибка в строках self.root.ids, а точнее в их столкновении
  • Вопрос задан
  • 1923 просмотра
Пригласить эксперта
Ответы на вопрос 1
sanya84
@sanya84
Фанатик Python 3
from kivy.lang import Builder
from kivymd.app import MDApp

KV = '''
BoxLayout:
    padding: "10dp"

    MDRaisedButton:
        id: button_show_text
        on_press: app.show_text()
    MDTextField:
        id: text_field
        hint_text: "Helper text on error (press 'Enter')"
        helper_text: "There will always be a mistake"
        helper_text_mode: "on_error"
        pos_hint: {"center_y": .5}

'''


class Test(MDApp):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.screen = Builder.load_string(KV)

    def build(self):
        self.screen.ids.text_field.bind(
            on_text_validate=self.set_error_message,
            on_focus=self.set_error_message,
        )
        return self.screen

    def set_error_message(self, instance_text_field):
        self.screen.ids.text_field.error = True
    def show_text(self):
        print(self.screen.ids.text_field.text)

Test().run()

6006da725635d411092016.png
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы