Weather app in python

Weather app in python

Hello Friends In this blog pose, we can study the “Weather app in python”.

For This Purpose, you need to install Tkinter module

pip install tkinter


Source Code:

import tkinter as tk
import requests

HEIGHT = 500
WIDTH = 600

def test_function(entry):
   print("This is the entry:", entry)

#{city name},{country code}
# a4aa5e3d83ffefaba8c00284de6ef7c3

def format_response(weather):
      name = weather['name']
      desc = weather['weather'][0]['description']
      temp = weather['main']['temp']

      final_str = 'City: %s \nConditions: %s \nTemperature (°F): %s' % (name, desc, temp)
      final_str = 'There was a problem retrieving that information'

   return final_str

def get_weather(city):
   weather_key = 'a4aa5e3d83ffefaba8c00284de6ef7c3'
   url = ''
   params = {'APPID': weather_key, 'q': city, 'units': 'imperial'}
   response = requests.get(url, params=params)
   weather = response.json()

   label['text'] = format_response(weather)

root = tk.Tk()

canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH, bg="yellow")

frame = tk.Frame(root, bg='#80c1ff', bd=5, ), rely=0.1, relwidth=0.75, relheight=0.1, anchor='n')

entry = tk.Entry(frame, font=40), relheight=1)

button = tk.Button(frame, text="Get Weather", font=40, command=lambda: get_weather(entry.get())), relheight=1, relwidth=0.3)

lower_frame = tk.Frame(root, bg='#80c1ff', bd=10), rely=0.25, relwidth=0.75, relheight=0.6, anchor='n')

label = tk.Label(lower_frame), relheight=1)




Hey Friends, Welcome to thetechbuddy. This blog is about technical or programming knowledge.

Leave a Reply