Search code examples
pythonkivykivymd

How to resolve this problem with RecycleView in Kivy?


I am trying to pass data from Menu class to Container class but I am having an exception TypeError: Container.__init__() missing 2 required positional arguments: 'source' and 'mipmap' I think the problel is not in Container class and rv. My app is so simple but I am still stack in this touble. I

my main.py

from kivymd.app import MDApp
from kivymd.uix.label import MDLabel
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.list import TwoLineAvatarIconListItem
from kivy.properties import StringProperty
from kivy.lang import Builder
from kivymd.uix.swiper import MDSwiper

class Container(TwoLineAvatarIconListItem):

    text = StringProperty()

class Menu(MDBoxLayout):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.rv.data = [{'text': 'hello world'}]


class App(MDApp):

    def build(self):
        Builder.load_file('main.kv')
        return Menu()

App().run() 

my main.kv

<Container>
    IcontLeftWidget:
        icon: 'home'
    IcontRightWidget:
        icon: 'home'

<Menu>
    rv: rv
    RecycleView:
        id: rv
        viewclass: 'Container'
        RecycleBoxLayout:
            default_size_hint: 1, None

Solution

  • Your viewclass of Container in your kv file is getting confused with a Container that is defined in KivyMD. The fix is to change the name of your viewclass. Try something like MyContainer. Also, your properties in the Container rule are miss-spelled (just remove the t).