I cant get lists to show up on my kivymd tabs

I am trying to create a chat app with kivymd but I can't get my lists to show up on the chat tad screen. I am getting the error:

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

 During handling of the above exception, another exception occurred:

 Traceback (most recent call last):
   File "c:/Users/Allano/Desktop/help/main.py", line 70, in <module>
     MainApp().run()
   File "C:\Users\Allano\Anaconda3\lib\site-packages\kivy\app.py", line 854, in run
     self.dispatch('on_start')
   File "kivy\_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
   File "c:/Users/Allano/Desktop/help/main.py", line 60, in on_start
     self.new_message("ERIK SANDBERG", "Hello World", "kivymd_logo.png")
   File "c:/Users/Allano/Desktop/help/main.py", line 65, in new_message
     self.root.ids.list.add_widget(new_message)
   File "kivy\properties.pyx", line 863, in kivy.properties.ObservableDict.__getattr__
 AttributeError: 'super' object has no attribute '__getattr__

I would like the list in the main.py file to load on startup of the app. I have tried for days to look for a solution but with no solution. any adjustments are welcomed with minimal alterations of the code format if possible. here is my code. I have removed some code to make it easy

main.kv

MDScreen: имя: "основной"

ScreenManager: идентификатор: screen_manager

Screen:

    MDBoxLayout:
        orientation: "vertical"
        size_hint: 1, 2

    BoxLayout:
        orientation: "vertical"

        MDToolbar:
            id: toolbar
            title: "name"
            size_hint: 1.0,0.05
            md_bg_color: 1, 1, 1, 1 
            elevation: 10              

        MDTabs:
            
            tab_indicator_anim: True
            color_indicator: 1, 1, 1, 1
            tab_indicator_height: ("3dp")

            Tab:
                text: "Threads"
                                                                                        
            Tab:
                text: "Chats"
                ScrollView:
                    MDList:
                        id: list

            Tab:
                text: "Post"
                Screen:
                    BoxLayout:
                        orientation: "vertical"

login.kv

 MDScreen:
    name: "login"
    
    Screen:
        MDBoxLayout:
            orientation: "vertical"
           
    MDRaisedButton:
        text: 'Enter'
        elevation: 2
        font_size: 35
        width: dp(200)
        elevation_nomal: 8
        size_hint: 0.85,0.06
        pos_hint: {'center_x':0.5,'center_y':0.38}
        on_press:
            root.manager.transition.direction = 'left' 
            root.manager.current = "main"
       

main.py

import os
from kivy.animation import Animation
from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.factory import Factory
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivymd.uix.picker import MDDatePicker
from kivy.core.window import Window
from kivy.uix.modalview import ModalView
from kivymd.uix.filemanager import MDFileManager
from kivymd.theming import ThemableBehavior
from kivy.properties import(
    ListProperty,
    NumericProperty,
    ObjectProperty,
    OptionProperty,
    StringProperty,
    BooleanProperty,
)
from kivymd.toast import toast
from kivymd.uix.dialog import MDDialog
from kivymd.uix.button import MDFlatButton, MDFillRoundFlatButton
from kivymd.uix.menu import MDDropdownMenu 
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivymd.uix.list import TwoLineAvatarIconListItem
from kivymd.uix.snackbar import Snackbar
from kivymd.uix.bottomsheet import MDCustomBottomSheet
from kivy.uix.button import Button
from kivymd.uix.useranimationcard import MDUserAnimationCard
from kivymd.uix.tab import MDTabsBase
from kivymd.uix.list import ImageLeftWidget

class Tabs(FloatLayout, MDTabsBase):
    '''Class implementing content for a tab on home screen'''


class MainApp(MDApp):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.title = "Main App"
        self.theme_cls.theme_style = "Dark" 
        self.theme_cls.primary_palette = "Cyan"
        self.theme_cls.primary_hue = "600"
        

    def change_screen(self,name):
        screen_manager.current = name

    def build(self):
        global screen_manager
        screen_manager = ScreenManager()
        screen_manager.add_widget(Builder.load_file("login.kv"))
        screen_manager.add_widget(Builder.load_file("Main.kv"))
        return screen_manager

    def on_start(self):
        self.new_message("ERIK SANDBERG", "Hello World", "kivymd_logo.png")
    
    def new_message(self, name, message, image_name):
        new_message = TwoLineAvatarIconListItem(text=name, secondary_text=message)
        new_message.add_widget(ImageLeftWidget(source=image_name))
        self.root.ids.list.add_widget(new_message)

 

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



    

1 ответ

Main.kv

Screen:
    name: "main"

    [...]

main.py

class MainApp(MDApp):

    [...]

    def new_message(self, name, message, image_name):
        [...]
        screen_manager.get_screen("main").ids.list.add_widget(new_message)
Другие вопросы по тегам