当我尝试将小部件(问题中的布局)添加到我修改为该布局的个性化ID时,会引发一个错误,我认为我无法识别个性化ID
gr_ly = GridLayout(id=i[1], rows=1)
self.LayoutGeneralCI.ids.realll.add_widget(gr_ly)
#Adding another widget to the custom id layout but just always puts me the widgets into the last layout executed
gr_ly.add_widget(self.DatosLayoutCI)
所有代码在这里
def selection_data_secciones(self):
self.mainwid.dataBase = sqlite3.connect("UserData")
self.mainwid.dataCursor = self.mainwid.dataBase.cursor()
self.mainwid.dataCursor.execute("SELECT * FROM SECCIONES")
fetch = self.mainwid.dataCursor.fetchall()
for i in fetch:
self.LayoutGeneralCI = LayoutGeneralCI(self.mainwid)
ref_idd = i[1]
gr_ly = GridLayout(id=i[1], rows=1)
print(type(gr_ly.id))
self.LayoutGeneralCI.ids.realll.add_widget(gr_ly)
print(self.LayoutGeneralCI.ids)
self.LayoutGeneralCI.ids.title_sect_lbl.text = i[1]
self.ids.container_ci.add_widget(self.LayoutGeneralCI)
for produ in self.mainwid.dataCursor.execute("SELECT * FROM MATERIALES"):
self.DatosLayoutCI = DatosLayoutCI(self.mainwid)
txtvar_ci = "Nombre: [b]{}[/b] \n".format(produ[1])
txtvar2_ci = "Proveedor: [b]{}[/b] \n".format(produ[3])
if produ[8] <= str(0):
txtvar3_ci = "Disponibilidad: [color=#FF0000][b]Agotado[/b][/color]"
else:
txtvar3_ci = "Disponibilidad: [color=#00FF00][b]Disponible[/b][/color]"
txtvargeneral_ci = txtvar_ci + txtvar2_ci + txtvar3_ci
self.DatosLayoutCI.ids.content_cill.text = txtvargeneral_ci
var_sectttion = self.mainwid.AgregarProductos.ids.section_product.text#
var_reference_id = produ[2]
gr_ly.add_widget(self.DatosLayoutCI)
self.mainwid.dataBase.commit() #DISCOMMENT NECCESARY
self.mainwid.dataBase.close()
结果是:
self.LayoutGeneralCI.ids.var.add_widget(self.DatosLayoutCI)
File "kivy\properties.pyx", line 841, in kivy.properties.ObservableDict.__getattr__
AttributeError: 'super' object has no attribute '__getattr__'
答案 0 :(得分:0)
继续将DatosLayoutCI小部件添加到最后一个小部件gr_ly
为了显示每个部分(SECCIONES)下的所有材料(材料),必须使用一个带有INNER JOIN的SQL语句或两个SELECT语句(嵌套的SELECT)。
def selection_data_secciones(self):
self.mainwid.dataBase = sqlite3.connect("UserData")
self.mainwid.dataCursor = self.mainwid.dataBase.cursor()
self.mainwid.dataCursor.execute("SELECT * FROM SECCIONES") # Sections
fetch = self.mainwid.dataCursor.fetchall()
for i in fetch:
self.LayoutGeneralCI = LayoutGeneralCI(self.mainwid)
ref_idd = i[1]
gr_ly = GridLayout(id=i[1], rows=1)
...
self.mainwid.dataCursor.execute("SELECT * FROM MATERIALES WHERE id=?", (gr_ly.id))
materials = self.mainwid.dataCursor.fetchall()
for produ in materials:
self.DatosLayoutCI = DatosLayoutCI(self.mainwid) # Datos = Data
...
gr_ly.add_widget(self.DatosLayoutCI)
self.mainwid.dataBase.commit() #DISCOMMENT NECCESARY
self.mainwid.dataBase.close()
self.LayoutGeneralCI.ids.var.add_widget(self.DatosLayoutCI)
File "kivy\properties.pyx", line 841, in kivy.properties.ObservableDict.__getattr__
AttributeError: 'super' object has no attribute '__getattr__'
在Python脚本中创建的ID与在kv文件中创建的ID不同。
Kv Language » Referencing Widgets
Kv Language » Accessing Widgets defined inside Kv lang in your python code
id: value
,坏-> id: 'value'
self.ids.realll
或self.ids['realll']
以Python脚本访问它self.ids
字典类型属性中。这意味着您还可以遍历这些小部件并访问它们的字典样式。id
是一个字符串self.ids.var
self.ids
gr_ly = GridLayout(id=str(i[1]))
#####adding a widget to the personalized id of layout
gr_ly.add_widget(self.DatosLayoutCI)
self.LayoutGeneralCI.ids.realll.add_widget(gr_ly)
#######all the code is in a function so i want to créate a layout that will #######contain the widgets with a personalized id and then calling the #######personalized id to add the widget in different and specific layouts##
####defining the layout and it's personalized id and adding to the class
gr_ly = GridLayout(id=str(i[1]))
#####adding a widget to the personalized id of layout
gr_ly.add_widget(self.DatosLayoutCI)
self.LayoutGeneralCI.ids.realll.add_widget(gr_ly)#####1 PRIMERA OPCION