Python 删除文件中给定id的小部件
我想使用我在KV文件中给对象的KV id删除GUI中特定屏幕中的小部件。 这是我的kv文件:Python 删除文件中给定id的小部件,python,kivy,Python,Kivy,我想使用我在KV文件中给对象的KV id删除GUI中特定屏幕中的小部件。 这是我的kv文件: <CreateAccountWindow>: name: "create" namee: namee mail: mail email:email FloatLayout: cols:1 canvas.before: Rectangle:
<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)
我读过一些建议用这种方法解决问题的帖子,但似乎不起作用。
我想问一下,删除这些小部件的正确方法是什么。
如果您有任何提示,我将不胜感激。您的
kv
中的layout
id在哪里?在给内部floatlayout一个id之后,我不知道您可以给一个布局一个id,我如何通过screen类访问它?与您在发布的代码中所做的完全一样。我知道,是的,它现在起作用了。非常感谢,答案很明显,但我不得不把布局也当作一个对象。
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)