python - 删除 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)
我已经阅读了建议以这种方式解决它的线程,但它似乎没有用。我想问一下删除小部件的正确方法是什么。将不胜感激任何提示谢谢。
解决方案
推荐阅读
- swift - Swift 中的 M13Checkbox 选定操作?
- google-cloud-platform - Dataproc 错误上的 Zepplin BigQuery 连接
- bash - 如何提取远程 VM 的操作系统版本并将其设置为远程 VM 上的环境变量,并在期望脚本中进一步使用?
- django - 如何使用 POST 请求从 Django 表单接收数据并在 Html 模板上呈现
- flutter - 为什么任何小部件都是无状态的?
- r - 我可以使用 Shiny observeEvent 观察哪些事件?
- android - 如何在打盹模式 8.0 Oreo 设备中获取 GPS 更新?
- angular - Angular 7+ 中的 ClassDefinition 有什么类似物吗?
- c# - 如何异步调用单个方法“n”次?
- html - 如何从 htmlelement (elementref) 获取子项宽度