How to remove a widget from a screen

I’m trying to make a screen with textinput a btn and a recycling view.
The btn add to the recycling view a card with the text of the textinput, each card has a trash-bin button to remove the card and the item from the list.

At the moment I can’t update the recycling view when i press the trash-bin button. I remove the item from the list but the card stay on the screen.

How can I fix this?

Here the code:

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

    WindowsManager:
        AggiungiRepartoWindow:           

<RepartiRV>
    viewclass:'RepartoCard'
    ListaRepartiBoxLayout:
        orientation: 'vertical'
        default_size_hint: 1, None 
        size_hint_y: None
        height: self.minimum_height
        
<RepartoCard>
    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.cancella_reparto()
        MDLabel:
            id:Label
            text: root.text
            adaptive_size: True
            color: "grey"
            pos_hint:{'center_x':0.1,'center_y':0.5}
            bold: True

<AggiungiRepartoWindow> 
    name:"Aggiungi_Reparto"
    nome:nome
    rvNome:rv_lista_reparti
    MDBoxLayout:
        orientation: 'vertical'
        
        MDFloatLayout:
            size_hint_y: None
            height:dp(100)
            MDTextField:
                id: nome
                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.crea_reparto()
                pos_hint: {"center_x": .8, "center_y":.5}
                size_hint_x: None
                width: dp(100)

                MDButtonText:
                    text: "Aggiungi"

        RepartiRV:
            id:rv_lista_reparti
        
                
.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.core.window import Window
from kivy.uix.screenmanager import Screen, ScreenManager
import Class
import pickle

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

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

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

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

class WindowsManager(ScreenManager):
    pass

class AggiungiRepartoWindow(Screen):
 
   def crea_reparto(self):
        nome = self.ids.nome.text
        rep = Class.Reparto(nome)
        self.ids.nome.text = ""
        lista_reparti.append(rep)
        with open('listareparti.pickle',"wb") as f:
            pickle.dump(lista_reparti,f)
        self.ids.rv_lista_reparti.refreshview(lista_reparti)
        return lista_reparti

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

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

class ListaRepartiBoxLayout(FocusBehavior, LayoutSelectionBehavior, RecycleBoxLayout):
    pass

class RepartoCard(MDCard, RecycleDataViewBehavior):
    index= None
    text= StringProperty()
    
    def refresh_view_attrs(self,rv, index, data):
        return super(RepartoCard, self).refresh_view_attrs(
            rv, index, data)
    
    def cancella_reparto(self):
        id= self.id
        for item in lista_reparti: 
            if str(item) == id:
                print(item)
                lista_reparti.remove(item)
        print(lista_reparti)

class CreaIntervento(MDApp):

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

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

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