How to remove a widget from screen and refresh the recycleview?

This is my first question, I’m new on kivy…

I want to add or remove a card from a list of card in a recyclingview.

So I have a screen with a text box and a button that I use to add the card to the RV, and on each card on the list, I have a trash button to remove the card from the list.

Now I can add the card to the list, but I don’t know how to remove the card from the list.

here the code:

.Py

from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.uix.recycleview import RecycleView
from kivy.uix.recycleview.views import RecycleDataViewBehavior
from kivy.uix.recycleboxlayout import RecycleBoxLayout
from kivy.uix.behaviors import FocusBehavior
from kivy.uix.recycleview.layout import LayoutSelectionBehavior
from kivymd.uix.card import MDCard
from kivy.properties import StringProperty, BooleanProperty, ObjectProperty
from kivy.uix.screenmanager import Screen, ScreenManager
import Class
import pickle


try:
    with open("list1.pickle","rb") as f:
        list1 = pickle.load(f)
except:
    list1 = []

class ScreenManager(ScreenManager):
    pass

class Screen1(Screen):

    def add_card(self):
        text = self.ids.text_field.text
        obj = Class.Reparto(text)
        self.ids.text_field.text = ""
        list1.append(obj)
        with open('list1.pickle',"wb") as f:
            pickle.dump(list1,f)
        self.ids.RV_List.refreshview(list1)
        return list1

class RV(RecycleView):
    def __init__(self, **kwargs):
        super(RV, self).__init__(**kwargs)
        self.data = [{'text': str(reparto.nome),'id':str(reparto)} for reparto in list1]   

    def refreshview(self, lista):
        self.data = [{'text': str(reparto.nome)} for reparto in lista] 

class RVBoxLayout(FocusBehavior, LayoutSelectionBehavior, RecycleBoxLayout):
     pass
    
class CardView(MDCard, RecycleDataViewBehavior):
    
    text= StringProperty()

    def remove_card(self):
        for item in list1: 
            if item.nome == self.ids.Label.text:
                list1.remove(item)
        MDApp.get_running_app().root.ids.RV.refreshview(list1)


class CreaIntervento(MDApp):

    def build(self):
        self.theme_cls.theme_style = "Light"
        return Builder.load_file("KV.kv")

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

.Kv

MDBoxLayout:
    orientation:'vertical'
    md_bg_color: app.theme_cls.primaryColor

    ScreenManager:
        id:screen_manager
        Screen1:           

<RV>
    viewclass:'CardView'
    RVBoxLayout:
        orientation: 'vertical'
        default_size_hint: 1, None 
        size_hint_y: None
        height: self.minimum_height
        

<CardView>
    style:'elevated'
    size_hint_y:None
    height: dp(80)
    MDRelativeLayout:
        
        MDIconButton:
            id:func_icon
            icon: "trash-can"
            pos_hint:{'center_x':0.9,'center_y':0.5}
            on_release:root.remove_card()
        MDLabel:
            id:Label
            text: root.text
            adaptive_size: True
            color: "grey"
            pos_hint:{'center_x':0.1,'center_y':0.5}
            bold: True

<Screen1> 
    name:"Aggiungi_Reparto"
    text_field:text_field
    rvNome:RV_List
    MDBoxLayout:
        orientation: 'vertical'

        MDFloatLayout:
            size_hint_y: None
            height:dp(100)
            MDTextField:
                id: text_field
                mode: "outlined"
                pos_hint: {"center_x": .4, "center_y":.5}
                size_hint_x: None
                width: dp(400)

                MDTextFieldHintText:
                    text: "Nome nuovo reparto"

                MDTextFieldHelperText:
                    
                MDTextFieldMaxLengthText:
                    max_text_length: 30
                        
            MDButton:
                style: "filled"
                on_release: root.add_card()
                pos_hint: {"center_x": .8, "center_y":.5}
                size_hint_x: None
                width: dp(100)

                MDButtonText:
                    text: "Aggiungi"

        RV:
            id:RV_List
                

I’ve tried to call a method from the RV, but without results.

New contributor

TestFour is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

OK I’ve find a solution:

def remove_card(self):
    for item in list1: 
        if item.nome == self.ids.Label.text:
            list1.remove(item)
    root= self.parent
    root= root.parent
    root.refreshview(list1)
    with open('list1.pickle',"wb") as f:
        pickle.dump(list1,f)
    return list1

Using parent I can use the refreshview() method of the RV class.

New contributor

TestFour is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật