This is my first question here and i am not a programmer by trade, i build machines and sometimes use programming to do secondary adjustments. This is part of a modbus HMI project in python. I create switches and labels iteratively but after that i cant reach their properties. As i said this was written with kivy, but no important kv code was used, just positioning.
class InputGrid(GridLayout):
def __init__(self,**kwargs):
super().__init__(**kwargs)
self.cols = 8
self.indicators=mp.readInputs(qty=48)
self.red = (1, 0, 0, 1)
self.green = (0, 1, 0, 1)
Clock.schedule_interval(self.updateLabels,1)
for i in range(0,48):
self.l = Label(text="input " + str(i+1))
if self.indicators[i] == False:
self.l.color=self.red
elif self.indicators[i] == True:
self.l.color = self.green
self.add_widget(self.l,i) #When i put in the index number self.ljust changes position...
def updateLabels(self,dt):
self.indicators=mp.readInputs(qty=48)
self.l.color = self.green #Here i want to be able to change all 48 label colors...
You can keep a list of the Labels
. For example, use self.labels
:
class InputGrid(GridLayout):
def __init__(self,**kwargs):
super().__init__(**kwargs)
self.labels = []
self.cols = 8
self.indicators=mp.readInputs(qty=48)
self.red = (1, 0, 0, 1)
self.green = (0, 1, 0, 1)
Clock.schedule_interval(self.updateLabels,1)
for i in range(0,48):
self.l = Label(text="input " + str(i+1))
self.labels.append(self.l)
if self.indicators[i] == False:
self.l.color=self.red
elif self.indicators[i] == True:
self.l.color = self.green
self.add_widget(self.l,i) #When i put in the index number self.ljust changes position...
def updateLabels(self,dt):
self.indicators=mp.readInputs(qty=48)
for l in self.labels:
l.color = self.green #Here i want to be able to change all 48 label colors...
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments