@Diyar

В чем может быть ошибка Kivy?

from distutils.command.build import build
from tkinter import INSERT
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivymd.app import MDApp
from kivy.core.window import Window
from kivymd.uix.textfield import TextInput
from kivymd.uix.button import MDFillRoundFlatButton
import sqlite3
from kivy.clock import Clock
from kivymd.uix.list import OneLineListItem

con = sqlite3.connect('my.db')
c = con.cursor()
c.execute("""CREATE TABLE IF NOT EXISTS post(
title TEXT NOT NULL,
main_text TEXT NOT NULL)""")
con.commit()
con.close()


Window.size = (412, 915)
build = Builder.load_string("""

:
MenuScreen:
AddPost:
ReadPost:

:
MDBoxLayout:
orientation: "vertical"

MDToolbar:
type: "top"
title: "Скорочтение"

MDBoxLayout:

orientation: "vertical"
padding:200, 550, 200, 550
spacing:25

MDRoundFlatIconButton:

text: "Добавить запись"
width: root.width*0.6
font_size: 40
icon: "plus"
on_release: root.manager.current = 'add'


MDRoundFlatIconButton:

text: "Читать на скорость"
width: root.width*0.6
font_size: 40
icon: "clock"
on_press: root.manager.current = 'read'


MDRoundFlatIconButton:

width: root.width*0.6
font_size: 40
icon: "eye"
text: "Внимательность"



:
MDBoxLayout:
orientation: "vertical"
MDToolbar:
type: "top"
title: "Добавить запись"
left_action_items: [['keyboard-backspace', lambda x: app.set_screen("menu")]]

MDBoxLayout:
orientation: "vertical"
padding:100, 200, 100, 600
spacing:45

MDTextField:
id: title
hint_text:"Описание"
pos_hint:{'center_x':.5,'center_y':.5}
font_size:"18dp"
line_color: "white"
width: 350
on_touch_down: if self.collide_point(*args[1].pos): self.text = ""
MDTextField:
id: main_text
hint_text:"Основной текст"
pos_hint:{'center_x':.5}
font_size:"18dp"
line_color: "white"
multiline: True
size_hint: (1.0, None)
max_height: 500
on_touch_down: if self.collide_point(*args[1].pos): self.text = ""
MDRoundFlatButton:
width: root.width * 0.75
font_size: "18dp"
text: "Сохранить"
halign: "center"
on_press: app.submit(root.ids.title.text, root.ids.main_text.text)



:
MDBoxLayout:
orientation: "vertical"
MDToolbar:
type: "top"
title: "Читать текст"
left_action_items: [['keyboard-backspace', lambda x: app.set_screen("menu")]]
MDBoxLayout:
orientation: "vertical"

MDList:
id: container
# OneLineAvatarIconListItem:
# on_release: print("Click!")
# text: "Текст"
# IconRightWidget:
# icon: "minus"
""")

class AddPost(Screen):

pass


class ReadPost(Screen):
pass

class MenuScreen(Screen):
pass

class MainApp(MDApp):

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.root = build

def set_screen(self, name):

self.root.current = name
print("ss")

def build(self):


sm = ScreenManager()
sm.add_widget(AddPost(name="add"))
sm.add_widget(ReadPost(name="read"))
sm.add_widget(MenuScreen(name="menu"))

return sm

def on_start(self):

con = sqlite3.connect("my.db")
c = con.cursor()
data = """SELECT * FROM post"""
c.execute(data)
data = c.fetchall()
for i in data:
self.ids.container.add_widget(
OneLineListItem(text=f"{i}")
)
con.close()
print("das")


def submit(self, title, main_text):

if title == '' or main_text == '':
print('eror')
else:
con = sqlite3.connect("my.db")
c = con.cursor()
c.execute("""INSERT INTO post(
title, main_text)
VALUES (?,?);""",
(title, main_text))
con.commit()
con.close()
print("Э")

def listText(self):
con = sqlite3.connect("my.db")
c = con.cursor()
data = """SELECT * FROM post"""
c.execute(data)
data = c.fetchall()
for i in data:
self.root.ids.container.add_widget(
OneLineListItem(text=f"{i}")
)
con.close()



MainApp().run()

Ошибка
Traceback (most recent call last):
File "kivy/properties.pyx", line 961, in kivy.properties.ObservableDict.__getattr__
KeyError: 'container'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/diarsavkatov/Documents/projects/read/main.py", line 215, in
MainApp().run()
File "/Users/diarsavkatov/Documents/projects/read/env/lib/python3.10/site-packages/kivy/app.py", line 954, in run
self._run_prepare()
File "/Users/diarsavkatov/Documents/projects/read/env/lib/python3.10/site-packages/kivy/app.py", line 949, in _run_prepare
self.dispatch('on_start')
File "kivy/_event.pyx", line 731, in kivy._event.EventDispatcher.dispatch
File "/Users/diarsavkatov/Documents/projects/read/main.py", line 178, in on_start
self.root.ids.container.add_widget(
File "kivy/properties.pyx", line 964, in kivy.properties.ObservableDict.__getattr__
AttributeError: 'super' object has no attribute '__getattr__'
  • Вопрос задан
  • 216 просмотров
Пригласить эксперта
Ответы на вопрос 1
WinXpisher
@WinXpisher
Попробуй в функции on_start поставить self. возле переменных
Ответ написан
Комментировать
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы