在我的应用程序中,我有一个标签列表:
self.alarmeon1 = Label(text="None", font_size='20sp', size=(100, 50), pos=(-120, 35))
self.add_widget(self.alarmeon1)
self.alarmeoff1 = Label(text="Nona", font_size='20sp', size=(100, 50), pos=(-40, 35))
self.add_widget(self.alarmeoff1)
#Label compteur alarme Channel 1
self.cptalarmeon1 = Label(text="0", font_size='20sp', size=(100, 50), pos=(-120, 5))
self.add_widget(self.cptalarmeon1)
self.cptalarmeoff1 = Label(text="0", font_size='20sp', size=(100, 50), pos=(-40, 5))
self.add_widget(self.cptalarmeoff1)
# Alarme Channel 2
self.alarmeon2 = Label(text="None", font_size='20sp', size=(100, 50), pos=(280, 35))
self.add_widget(self.alarmeon2)
self.alarmeoff2 = Label(text="None", font_size='20sp', size=(100, 50), pos=(360, 35))
self.add_widget(self.alarmeoff2)
#Label compteur alarme Channel 2
self.cptalarmeon2 = Label(text="0", font_size='20sp', size=(100, 50), pos=(280, 5))
self.add_widget(self.cptalarmeon2)
self.cptalarmeoff2 = Label(text="0", font_size='20sp', size=(100, 50), pos=(360, 5))
self.add_widget(self.cptalarmeoff2)
# Alarme Channel 3
self.alarmeon3 = Label(text="None", font_size='20sp', size=(100, 50), pos=(-120, -183))
self.add_widget(self.alarmeon3)
self.alarmeoff3 = Label(text="None", font_size='20sp', size=(100, 50), pos=(-40, -183))
self.add_widget(self.alarmeoff3)
#Label compteur alarme Channel 3
self.cptalarmeon3 = Label(text="0", font_size='20sp', size=(100, 50), pos=(-120, -213))
self.add_widget(self.cptalarmeon3)
self.cptalarmeoff3 = Label(text="0", font_size='20sp', size=(100, 50), pos=(-40, -213))
self.add_widget(self.cptalarmeoff3)
# Alarme Channel 4
self.alarmeon4 = Label(text="None", font_size='20sp', size=(100, 50), pos=(280, -183))
self.add_widget(self.alarmeon4)
self.alarmeoff4 = Label(text="None", font_size='20sp', size=(100, 50), pos=(360, -183))
self.add_widget(self.alarmeoff4)
#Label compteur alarme Channel 4
self.cptalarmeon4 = Label(text="0", font_size='20sp', size=(100, 50), pos=(280, -213))
self.add_widget(self.cptalarmeon4)
self.cptalarmeoff4 = Label(text="0", font_size='20sp', size=(100, 50), pos=(360, -213))
self.add_widget(self.cptalarmeoff4)
我的目标是将这些难看的标签“转换”为标签的“列表”,以便将下面代码中的self.cptalarmeon1.text=str(passerelle.cptalarmondut1)
替换为:self.cptalarmeon[i].text=str(passerelle.cptalarmondut1)
for i in passerelle.dut:
if(i.A_mA>alarm_awake_mA):
Logger.warning("alarme: seuil dépassé")
passerelle.cptalarmondut1=passerelle.cptalarmondut1+1
Logger.warning("alarme: valeur de cptalarmondut1 : {}".format(passerelle.cptalarmondut1))
self.cptalarmeon1.text=str(passerelle.cptalarmondut1)
print >> i.fic_err, ";".join([date, str(i.A_mA), "mA", "Awake"])