我想访问孩子的id来决定是否删除小部件。我有以下代码:
在主.py在
#!/usr/bin/kivy
# -*- coding: utf-8 -*-
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
class Terminator(BoxLayout):
def DelButton(self):
print("Deleting...")
for child in self.children:
print(child)
print(child.text)
if not child.id == 'deleto':
print(child.id)
#self.remove_widget(child)
else:
print('No delete')
class TestApp(App):
def build(self):
pass
if __name__ == '__main__':
TestApp().run()
在试验电压在
^{pr2}$但是,当用:print(child.id)
打印id时,它总是返回:None
。即使print(child.text)
正确返回Delete
或{deleto
,而是{
正如您在documentation中看到的:
描述了从Python代码访问id here。工作示例:
要跳过删除带有“Delete”标签的按钮,可以检查其
^{pr2}$text
属性。从循环内部删除Hovewer将导致错误,因为在您迭代的列表更改后,某些子项将被跳过:必须创建要删除的子项列表:
在您的情况下:
相关问题 更多 >
编程相关推荐