Good day. I am currently learning Python and difficulty has arisen. There is a small weather widget. It is necessary for him to update the information in the n-th number of seconds. How to implement it? Thanks in advance

owm = pyowm.OWM('87c7712a9b72646a269102230858837b') observation = owm.weather_at_place("Donetsk") w = observation.get_weather() temperature = w.get_temperature('celsius')['temp'] status = w.get_status() root = Tk() root.title('Погода') root.geometry('150x100') label = Label(text='Температура: '+ str(temperature)) label2 = Label(text='Небо: ' + str(status)) label.grid() label2.grid() root.mainloop() 

    1 answer 1

    An example of updating data every second:

     API_KEY = '87c7712a9b72646a269102230858837b' def get_weather_info(api_key, place): import pyowm owm = pyowm.OWM(api_key) observation = owm.weather_at_place(place) w = observation.get_weather() temperature = w.get_temperature('celsius')['temp'] status = w.get_status() return temperature, status from tkinter import * root = Tk() root.title('Погода') root.geometry('150x100') label = Label() label2 = Label() label.grid() label2.grid() def update_clock(): temperature, status = get_weather_info(api_key=API_KEY, place='Donetsk') print(temperature, status) label.configure(text='Температура: ' + str(temperature)) label2.configure(text='Небо: ' + str(status)) # Вызов каждую секунду root.after(1000, update_clock) # Сразу вызываем, чтобы виджеты заполнились update_clock() root.mainloop() 

    Shl. OpenWeatherMap can sometimes understand the Cyrillic alphabet, so you can specify Донецк in place and the same result will be

    • Thank you very much. I'll go and delve into the code. - Dennis