What I am trying to do with the following code is read from arduino serial and update a label with that data every few seconds.
When I run the code it only gets/updates
It appears that you misunderstand how the TK mainloop works. It is not, as you described, a loop between calling Tk()
and mainloop()
, but rather within Tkinter, external of your programs code.
In order to have a loop, updating a label, you would have to specifically write a loop, using Tk's after
method, calling an iterable function over and over.
You could make a function like this to do what you want:
def update_label():
data= float(arduinoSerialData.readline())
templabel.config(text=str(data)) #Update label with next text.
Joes.after(1000, update_label)
#calls update_label function again after 1 second. (1000 milliseconds.)
I am unsure of how the arduino data is retrieved, so you may need to modify that slightly to have the correct data. This is a general premise though for creating a loop in the manner you described.