KivyMD Remove a Expansion Panel

272 Views Asked by At

I'm having trouble finding the solution in how to remove an expansion panel which inside of it it contains TwoLineAvatarListItem with a IconLeftWidget, and below that is a MDCard with two MDlabels for text. I've tried to use self.root.ids.remove_widget() but it does not do anything. I've tried many ways and have not found the solution. Here is the code please feel free to view. Thanks

kv. file

<Content>:
    adaptive_height: True
    #size_hint: 1, None
    size_hint_y: None
    height: self.minimum_height
    orientation: 'vertical'

    TwoLineAvatarListItem:
        text: "Message"
        secondary_text: 'to: @gmail.com'
        IconLeftWidget:
            icon: 'email'


    MDCard:
        orientation: "vertical"
        padding: "8dp"
        size_hint: None, None
        size: "280dp", "180dp"
        pos_hint: {"center_x": .5, "center_y": .5}

        MDLabel:
            text: "Title"
            theme_text_color: "Secondary"
            size_hint_y: None
            height: self.texture_size[1]


        MDSeparator:
            height: "1dp"

        MDLabel:
            text: "Body"

ScreenManager:
    Screen:
        id: messages
        name: 'messages'
        BoxLayout:
            orientation: 'vertical'
            MDToolbar:
                title: "Messages Center"
                elevation:8
                MDIconButton:
                    icon: 'arrow-left'
                    on_press: screen_manager.current = "main_app_screen"
                    theme_text_color: 'Custom'
                    md_bg_color: app.theme_cls.primary_color
            ScrollView:
                GridLayout:
                    cols: 1
                    size_hint_y: None
                    height: self.minimum_height
                    id: box

.py python file

class DemoApp(MDApp):
    def on_start(self):
        for i in range(10):
            panel = MDExpansionPanel(
                    icon=f"{images_path}folder.png",
                     content=Content(),
                    panel_cls=MDExpansionPanelTwoLine(
                        text='',
                        secondary_text=str(i) + ' email: [email protected]',))

            self.root.ids.box.add_widget(panel)

DemoApp().run()
1

There are 1 best solutions below

1
On BEST ANSWER
<Content>:
    [...]


    MDCard:
        [...]

        MDRaisedButton:
            text: "REMOVE"
            on_release: app.remove(root)

        [...]



class DemoApp(MDApp):
    [...]

    def remove(self, content):
        self.root.ids.box.remove_widget(content.parent)