@Ilya_224

AttributeError: 'super' object has no attribute '__getattr__'. Did you mean: '__setattr__'?

from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.image import AsyncImage
from kivy.uix.label import Label
from kivy.uix.popup import Popup
from kivy.uix.scrollview import ScrollView

from kivymd.app import MDApp
from kivymd.uix.button import MDRectangleFlatIconButton, MDFloatingActionButtonSpeedDial,MDIconButton
from kivy.uix.togglebutton import ToggleButton
from kivymd.uix.screen import MDScreen
from kivymd.uix.textfield import MDTextField
from kivymd.uix.tab import MDTabsBase


class ParserApp(MDApp):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.markets = []
self.results_popup = None


def open_marketplaces(self, instance):
popup_content = BoxLayout(orientation="vertical")
marketplace_buttons = []
for marketplace_name in ["Туда","Сюда"]:
button = ToggleButton(text=marketplace_name)
button.bind(on_release=self.select_marketplace)
marketplace_buttons.append(button)
popup_content.add_widget(button)
popup = Popup(title="Слова", content=popup_content, size_hint=(0.8, 0.7), size=(400, 400))
popup.open()

def select_marketplace(self, instance):
marketplace_name = instance.text
if marketplace_name in self.markets:
self.markets.remove(marketplace_name)
instance.state = "normal"
else:
self.markets.append(marketplace_name)
instance.state = "down"

def start_search(self, instance):
# product_name = self.product_input.text
product_name = self.root.ids.text_field_error.text

results = []
if 'Туда' in marketplaces:
wildberries_results = self.parse_wildberries(product_name)
results.extend(wildberries_results)
if 'Сюда' in marketplaces:
ozon_results = self.parse_ozon(product_name)
results.extend(ozon_results)


return []

def display_results(self, results):
popup_content = BoxLayout(orientation="vertical")

scroll_view = ScrollView()
grid_layout = GridLayout(cols=1, spacing=10, size_hint_y=None)
grid_layout.bind(minimum_height=grid_layout.setter('height'))

for result in results[:5]: # Ограничим вывод на экран первыми 5 товарами
image = AsyncImage(source=result['image'])
label_text = f"Товар: {result['name']}\nЦена: {result['price']}"
label = Label(text=label_text, size_hint_y=None, height=150)
grid_layout.add_widget(image)
grid_layout.add_widget(label)

scroll_view.add_widget(grid_layout)
popup_content.add_widget(scroll_view)

self.results_popup = Popup(title="Результаты поиска", content=popup_content, size_hint=(0.8,0.7),
size=(800, 600))
self.results_popup.open()





def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Orange"
screen = MDScreen()


product_input = MDTextField(
id="text_field_error",
hint_text="Введите название слова",
helper_text="Здесь должен быть текст",
helper_text_mode="persistent",
pos_hint={"center_x": .5, "center_y": .9},
size_hint_x=.5,
)
setting=MDIconButton(
icon="cog",
size_hint=(0.2,.2),
pos_hint={"center_x": .9, "center_y": .1})
setting.bind(on_release=self.open_settings)
marketplases=MDIconButton(
icon="shopping",
size_hint=(0.2,.2),
pos_hint={"center_x": .1, "center_y": .1})
marketplases.bind(on_release=self.open_marketplaces)


search_button = MDRectangleFlatIconButton(
text="Начать поиск",
icon="language-python",
line_color=(0, 0, 0, 0),
pos_hint={"center_x":.5,"y":.2}
)
search_button.bind(on_release=self.start_search)

screen.add_widget(product_input)
screen.add_widget(search_button)
screen.add_widget(setting)
screen.add_widget(marketplases)


return screen

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

После запуска кода все идет хорошо,но после нажатия на кнопку "Начать поиск" мне выдает ошибку :


Traceback (most recent call last):
File "kivy\properties.pyx", line 961, in kivy.properties.ObservableDict.__getattr__
KeyError: 'text_field_error'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\User1\MyRarserApp\jdjbfjdgbk.py", line 127, in
ParserApp().run()
File "C:\Python311\Lib\site-packages\kivy\app.py", line 956, in run
runTouchApp()
File "C:\Python311\Lib\site-packages\kivy\base.py", line 574, in runTouchApp
EventLoop.mainloop()
File "C:\Python311\Lib\site-packages\kivy\base.py", line 339, in mainloop
self.idle()
File "C:\Python311\Lib\site-packages\kivy\base.py", line 383, in idle
self.dispatch_input()
File "C:\Python311\Lib\site-packages\kivy\base.py", line 334, in dispatch_input
post_dispatch_input(*pop(0))
File "C:\Python311\Lib\site-packages\kivy\base.py", line 302, in post_dispatch_input
wid.dispatch('on_touch_up', me)
File "kivy\_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
File "C:\Python311\Lib\site-packages\kivymd\uix\button\button.py", line 1187, in on_touch_up
return super().on_touch_up(touch)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\kivymd\uix\behaviors\ripple_behavior.py", line 404, in on_touch_up
return super().on_touch_up(touch)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\kivy\uix\behaviors\button.py", line 179, in on_touch_up
self.dispatch('on_release')
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 1231, in kivy._event.EventObservers._dispatch
File "C:\Users\User1\MyRarserApp\jdjbfjdgbk.py", line 46, in start_search
product_name = self.root.ids.text_field_error.text
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "kivy\properties.pyx", line 964, in kivy.properties.ObservableDict.__getattr__
AttributeError: 'super' object has no attribute '__getattr__'. Did you mean: '__setattr__'?
[Finished in 13.9s]

Please say me,how can I change it

I already tryed read documentation and just tryed search some option,but still anthing

I thing,that it because of ,that string:
product_name = self.root.ids.text_field_error.text
  • Вопрос задан
  • 72 просмотра
Пригласить эксперта
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы
21 февр. 2024, в 14:10
1000 руб./за проект
21 февр. 2024, в 14:06
3000 руб./за проект
21 февр. 2024, в 14:02
3500 руб./за проект