Hi
i have one list .
I want to update Progressbar from list elements.
# this code works
self.prograssBar1["value"] = 12
#but this code does not works,
#updating value from list
self.prograssBar1["value"] = int(spData[1:2])
how to solve this issue ?
What is progressBar1? What is spData?
My guess is progresBar1 is a tkinter.Progressbar and that spData is a list of floats?. To set the progress bar value equal to the number in spData[1], use:
self.prograssBar1["value"] = int(spData[1])
Next time include more surrounding code to provide context or give a more detailed explanation.
progressbar is widget provided by tkinter.
spData[1:2] is element of list.
spData[1:2] is a list containing spData[1]. spData[1:3] is a list containing spData[1] and spData[2]. I guess my question should have been "what is spData[1]? What do you have sored in your list?
my list
['#', '336', '908', '120', '863', '789', '3', '\n']
but when i tried to print list like this, i got error
print(spData[2]) #print 2nd element of list
print(spData[3]) #print 3rd element of list
error is
IndexError: list index out of range
here is my actual code
i am receiving data from serial port.
received data is comma separated value followed by "\n"
myData = self.arduinoSerialData.readline()
serData = myData.decode('ascii')
# serData = myData.decode("utf-8")
print(serData)
if len(serData) > 1:
spData = serData.split(',')
print(spData)
print(spData[2]) # this line generate error
Your list is not ['#', '336', '908', '120', '863', '789', '3', '\n']. If it were, spData[2] would be '120'.
Maybe spData is a list of lists?
Please supply the code that creates spData.
myData = self.arduinoSerialData.readline()
serData = myData.decode('ascii')
# serData = myData.decode("utf-8")
print(serData)
if len(serData) > 1:
spData = serData.split(',')
print(spData)
print(spData[2]) # this line generate error
What do you see printed when you call "print(spData)"