Python Tkinter GUI Script to Make a Weather Application Using Open Weather Map API Full Project For Beginners

Python Tkinter GUI Script to Make a Weather Application Using Open Weather Map API Full Project For Beginners


Welcome folks today in this post we will be building weather application using open weather map api in tkinter. All the source code of application is given below.




Get Started




In order to get started we need to install python inside our system. And now we need to install tkinter library by using the pip command


pip install tkinter


And now we need to make an file inside the root directory and copy paste the below code


And now you need to have a open weather map api and get an api key like this as shown below.






And now copy paste the api key inside this below code inside the file



from tkinter import *
import tkinter as tk
from datetime import datetime
from PIL import ImageTk , Image
import requests
from tkinter import messagebox

class Weather():

        def weather_report(self):
                self.url = ""
                self.cityname =  self.loc.get(1.0,END)
                self.api_key = '64f61566457c1a48b4f301389ba59786'
       = requests.get(self.url+self.cityname+'&appid='+self.api_key).json()

                if['cod'] == '404':
                        messagebox.showerror('Error','City Not Found !!')
                         self.location['text'] =['name'] + "," +['sys']['country']
                         self.c =['main']['temp_max'] - 273.15
                         self.f = self.c*9/5+32
               ['text'] =['weather'][0]['main']
               ['font'] = ('verdana',20,'bold')
                         self.temperature['text'] = f'{self.c}°C \n {self.f}°F'
                         self.temperature['font'] = ('verdana',15,'bold')
                         self.humidity['text'] =['main']['humidity']
                         self.humidity['font'] = ('verdana',15,'bold')
                         self.pressure['text'] =['main']['pressure']
                         self.pressure['font'] = ('verdana',15,'bold')


        def __init__(self):
                self.root = tk.Tk()
                self.root.title("Weather Application")

                self.header = Label(self.root,width=100,height=2,bg="#00274c")

                self.font = ('verdana',10,'bold')

       = Label(self.root,,bg="#00274c",fg="white",font=self.font)

                self.heading = Label(self.root,text="Weather Report",bg="#00274c",fg="white",font=self.font)

                self.location = Label(self.root,text="NA-/",bg="#00274c",fg="white",font=self.font)

                self.img = ImageTk.PhotoImage('icon.png'))
                self.image = Label(self.root,image=self.img)

       = Label(self.root,text="City or Country Name",fg="#00274c",font=self.font)

                self.loc = Text(self.root,width=25,height=2)

                self.button = Button(self.root,text="Search",bg="#00274c",fg="white",font=self.font,relief=RAISED,borderwidth=3,command=self.weather_report)

                self.line1 = Label(self.root,bg="#00274c",width=20,height=0)
                self.line2 = Label(self.root,bg="#00274c",width=20,height=0)

       = Label(self.root,text="Weather Report",bg="#00274c",fg="white",font=self.font,padx=10)

                self.img2 = ImageTk.PhotoImage('icon2.png'))
                self.image2 = Label(self.root,image=self.img2)
       = Label(self.root,text="NA/-",fg="#00274c",font=self.font)

                self.img3 = ImageTk.PhotoImage('icon3.png'))
                self.image3 = Label(self.root,image=self.img3)
                self.temperature = Label(self.root,text="NA/-",fg="#00274c",font=self.font)

                self.img4 = ImageTk.PhotoImage('icon4.png'))
                self.image4 = Label(self.root,image=self.img4)
                self.humidity = Label(self.root,text="NA/-",fg="#00274c",font=self.font)

                self.img5 = ImageTk.PhotoImage('icon5.png'))
                self.image5 = Label(self.root,image=self.img5)
                self.pressure = Label(self.root,text="NA/-",fg="#00274c",font=self.font)


if __name__ == '__main__':



See also  Python 3 json2excel Library Script to Convert JSON File or Raw JSON to Excel (XLSX) File Full Project For Beginners


And now if you execute the application by executing the below command






Leave a Reply