I'm new with Python, and am still experimenting a bit at the moment. I have a weather station at home that is linked to a JSON Web API. Via Python I would like to read the temperature on a screen.
The problem that i'm having is that the temperature is not updating itselfs. When the Python progrm starts its getting the correct temperature. But if the temperature changes, the python script. doesn't change.
import urllib.request
import json
from tkinter import *
import tkinter as tk
while True:
key = "1234"
method = "getTemp"
data = json.load(urllib.request.urlopen('http://IP.COM/api/api.php?key=' + key + "&request=" + method))
temp = (data[u'temp'])
root = Tk()
root.title("Temperature board")
root.configure(background='#545454')
cv = tk.Canvas(width=1000, height=1000, background='#545454')
timeLabel = cv.create_text(200, 360, fill="white", text=temp, font=('Arial', 100))
cv.pack()
root.mainloop()
I tried to create a loop to solve the problem, but it didn't seem to work.