如何从我的数据集中删除已从KivyMD的GUI中删除的项目

时间:2020-09-09 19:02:59

标签: python kivy kivy-language kivymd

当我按下垃圾箱图标按钮时,所选的OneLineListItem从GUI中删除。不幸的是,它没有从我的数据表中删除,因此当我重新启动应用程序时它将再次出现。但是我不知道如何将方法on_start / remove_item与我的数据表连接。您有什么想法可以解决这个问题吗?

仅是代码的重要部分

class MainApp(MDApp):

def build(self):
    self.theme_cls.primary_palette = "BlueGray"

def on_start(self):
    df = pd.read_csv("date.csv", index_col=False)
    for i in df.index:
        self.root.ids.md_list.add_widget(
            SwipeToDelete(text=df["Name"][i])

        )

def remove_item(self, instance):
    df = pd.read_csv("date.csv")
    self.root.ids.md_list.remove_widget(instance)

还有我的东西(仅是重要部分)

<SwipeToDelete>:
size_hint: 0.8, 0.8
pos_hint: {"center_x": 0.5, "center_y": 0.5}
height: content.height
type_swipe: "hand"
anchor:"left"

MDCardSwipeLayerBox:
    padding: "8dp"

    MDIconButton:
        icon:"trash-can"
        pos_hint: {"center_x":0.5, "center_y":0.5}
        on_release:
            app.remove_item(root)

MDCardSwipeFrontBox:

    TwoLineIconListItem:
        id: content
        text: root.text
        secondary_text: app.get_date_item()
        _no_ripple_effect: True
        IconLeftWidget:
            icon:"account"

0 个答案:

没有答案
相关问题