首页 > 解决方案 > 删除 KV 文件中给定 id 的小部件

问题描述

我想使用我在 kv 文件中给对象的 KV id 删除 GUI 内特定屏幕中的小部件。这是我的 kv 文件:

<CreateAccountWindow>:
    name: "create"

    namee: namee
    mail: mail
    email:email
    
    FloatLayout:
        cols:1

        canvas.before:
            Rectangle:
                pos: self.pos
                size: self.size
                source: "doorway.jpg"
            
        FloatLayout:
            size: root.width, root.height/2

            Label:
                text: "Add a person to the Database"
                size_hint: 0.8, 0.2
                color: 0,0,0,1
                pos_hint: {"x":0.1, "top":0.95}
                font_size: (root.width**2 + root.height**2) / 14**4


            Label:
                size_hint: 0.5,0.12
                pos_hint: {"x":0, "top":0.8}
                text: "Name: "
                color: 0,0,0,1
                font_size: (root.width**2 + root.height**2) / 14**4

            Label:
                id:mail
                text: "Email:"
                size_hint: 0.5,0.12
                color: 0,0,0,1
                pos_hint: {"x":0, "top":0.6}
                font_size: (root.width**2 + root.height**2) / 14**4
            

            TextInput:
                pos_hint: {"x":0.5, "top":0.8}
                size_hint: 0.4, 0.12
                id: namee
                multiline: False
                font_size: (root.width**2 + root.height**2) / 14**4
            
            TextInput:
                id: email
                pos_hint: {"x":0.5, "top":0.6}
                size_hint: 0.4, 0.12
                multiline: False
                font_size: (root.width**2 + root.height**2) / 14**4


        Button:
            pos_hint:{"x":0.2,"y":0.3}
            size_hint: 0.6, 0.15
            font_size: (root.width**2 + root.height**2) / 14**4
            text: "Already In the dataset? Request Entry"
            on_release:
                root.manager.transition.direction = "left"
                root.login()

        Button:
            pos_hint:{"x":0.2,"y":0.1}
            size_hint: 0.6, 0.15
            text: "Submit"
            font_size: (root.width**2 + root.height**2) / 14**4
            on_release:
                root.manager.transition.direction = "left"
                root.submit()


<LoginWindow>:
    name: "login"

    FloatLayout:

        canvas.before:
            Rectangle:
                pos: self.pos
                size: self.size
                source: "lock.jpg"
        Button:
            pos_hint:{"x":0.6,"y":0.5}
            size_hint: 0.3, 0.1
            font_size: (root.width**2 + root.height**2) / 14**4
            text: "Request Entry"
            on_release:
                root.manager.transition.direction = "up"
                root.loginBtn()


<MainWindow>:
    n: n
    out: out


    FloatLayout:

        canvas.before:
            Rectangle:
                pos: self.pos
                size: self.size
                source: "doorway.jpg"

        Label:
            id: n
            pos_hint:{"x": 0.1, "top":0.9}
            size_hint:0.8, 0.2
            text: "Username: "

        Button:
            pos_hint:{"x":0.35,"y":0.6}
            size_hint: 0.3, 0.1
            font_size: (root.width**2 + root.height**2) / 15**4
            text: "Add a person"
            on_release:
                root.manager.transition.direction = "right"
                root.createBtn()
        Button:
            pos_hint:{"x":0.35,"y":0.45}
            size_hint: 0.3, 0.1
            font_size: (root.width**2 + root.height**2) / 15**4
            text: "Edit permmited residents"
            on_release:
                root.manager.transition.direction = "right"
                root.deleteBtn()

        Label:
            id: out
            pos_hint:{"x": 0.1, "top":0.1}
            size_hint:0.8, 0.2
            color: 0,0,0,1
            text: "press Out if you would like to go back to the Entry screen\n"


        Button:
            pos_hint:{"x":0.35, "y": 0.1}
            size_hint:0.3,0.1
            font_size: (root.width**2 + root.height**2) / 15**4
            text: "Out"
            on_release:
                app.root.current = "login"
                root.manager.transition.direction = "down"

<EditDatabase>:

    fc: fc
    BoxLayout:
        orientation: 'vertical'

        canvas.before:
            Rectangle:
                pos: self.pos
                size: self.size
                source: "doorway.jpg"

        BoxLayout:
            size_hint_y: None
            height: sp(52)

            Button:
                text: 'Icon View'
                on_press: fc.view_mode = 'icon'
            Button:
                text: 'List View'
                on_press: fc.view_mode = 'list'

        FileChooser:
            id: fc
            rootpath: "Face/Faces"
            dirselect: True
            multiselect: True
            FileChooserIconLayout
            FileChooserListLayout
        
        BoxLayout:
            size_hint_y: None
            height: sp(52)

            Button:
                text: "Out"
                on_release:
                    app.root.current = "main"
                    root.manager.transition.direction = "down"

            Button:
                text: "Delete"
                on_release:
                    root.deleteBtn(fc.selection)

            Button:
                text: "Update"
                on_release:
                    root.updateBtn(fc.selection)

在 CreateAccountWindow 中,我想删除带有 id email 的标签和带有 id 邮件的文本输入。

class CreateAccountWindow(Screen):
    namee = ObjectProperty(None)
    mail = ObjectProperty(None)
    email = ObjectProperty(None)

    def submit(self):
        username = self.namee.text
        if(db.first_login()):
            self.ids.layout.remove_widget(self.email)
            self.ids.layout.remove_widget(self.mail)

我已经阅读了建议以这种方式解决它的线程,但它似乎没有用。我想问一下删除小部件的正确方法是什么。将不胜感激任何提示谢谢。

标签: pythonkivy

解决方案


推荐阅读