我有这个ids的序列。
self.ids.cuarta_pantalla.ids.container.ids.pre_1.ids.Si
在这种情况下,container具有70个不同的ID [从pre_1到pre_70],每个pre_(x)具有三个不同的ID [Si,MasMenos] >,No]对应于一组CheckBoxes。
如果我想使用其属性value
来了解单个复选框的状态,我将被迫这样编写所有语句。self.ids.cuarta_pantalla.ids.container.ids.pre_1.ids.Si.value
。
所以,我该如何遍历ID?
我尝试使用方括号self.ids.cuarta_pantalla.ids.container.ids['pre_1']
,但它返回的内容我无法调用任何方法。
带方括号的打印:<weakref at 0x125F7118; to 'BoxLayout' at 0x125F30D0>
用点符号打印:<kivy.uix.boxlayout.BoxLayout object at 0x125F30D0>
这是我创建对象的方式:
for idx in range(70):
BoxContainer = BoxLayout()
# Repeat this two more times with MasMenos and No
check1 = CheckBox(group= f"p_{idx+1}")
BoxContainer.add_widget(check1)
BoxContainer.ids['Si'] = weakref.ref(check1)
#Adding the BoxContainer with CheckBoxes to the container
self.ids.cuarta_pantalla.ids.container.add_widget(BoxContainer)
self.ids.cuarta_pantalla.ids.container.ids[f'pre_{idx+1}'] = weakref.ref(BoxContainer)
我有这个ID序列。 self.ids.cuarta_pantalla.ids.container.ids.pre_1.ids.Si在这种情况下,容器具有70个不同的ID [从pre_1到pre_70],每个pre_(x)具有三个不同的ID [...
不需要使用weakref
,每次使用add_widget
时,都会在添加了对象的对象中添加一个称为children