Weather is one of the most crucial aspects of our life. It dictates the different kinds of activities that we would like to plan throughout the day, week, or month. One of the older methods of reading weather patterns is to look at the sky and predict whether it would stay sunny, rain, or have a humid weather condition.
Tkinter: It is a built-in python library for making GUI using tkinter toolkit. Requests: It is a library which helps in fetching the data with the help of URL.
Firstly, we have to use a weather API for fetching the data from the Open Weather Map website by generating an API key, and then we need to create a configuration file to store the key. And finally using that configuration file in the python script.
Login in the Open Weather Map Go to the API section. Then in the Current Weather Data section click on the Api doc.
imported required modules
import requests from tkinter import *
app = Tk()
//add title
app.title("Weather App")
//adjust window size
app.geometry("300x300")
weather_l = Label(app, text="")
weather_l.pack()
app.mainloop()
def getweather(city):
result = requests.get(url.format(city))
if result:
json = result.json()
city = json['name']
final = [city]
return final
else:
print("NO Content Found")
Weather , plays a crucial role in our daily life. Hence, it is highly beneficial to develop a weather application that will help us track this integral element of nature successfully so that we can all plan our schedules accordingly and choose what would be the best course of action to go about in our daily life.