0% found this document useful (0 votes)
8 views5 pages

API Weather

Uploaded by

vidya gubbala
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

API Weather

Uploaded by

vidya gubbala
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

HANDS ON PROJECT

OPEN WEATHERMAP API APP

OPEN WEATHERMAP API APP: This is a simple GUI-based Weather Application built with
Python's tkinter library and the OpenWeatherMap API. The app allows users to enter the name of
a city and retrieve current weather information including temperature and a brief description of the
weather conditions.

CODE:

import tkinter as tk
import requests

# OpenWeatherMap API Key (Replace with your actual API key)


API_KEY = "cd89c6d89eb079083e096d648fd92b2c"
BASE_URL = "[Link]

def get_weather():
city = city_entry.get().strip() # Get user input & remove extra spaces
if not city:
weather_label.config(text="Please enter a city name!")
return

# API request with user input


response = [Link](BASE_URL, params={"q": city, "appid": API_KEY, "units":
"metric"})

if response.status_code == 200:
data = [Link]()
city_name = [Link]("name", "Unknown City")
temperature = data["main"]["temp"]
description = data["weather"][0]["description"]
weather_label.config(text=f"{city_name}: {temperature}°C, {description}")
else:
weather_label.config(text="City not found!")

# GUI Setup
root = [Link]()
[Link]("Weather App")

# Input field
city_entry = [Link](root)
city_entry.pack()

# Button to fetch weather


[Link](root, text="Get Weather", command=get_weather).pack()

# Label to display weather info


weather_label = [Link](root, text="Enter a city name and press the button.")
weather_label.pack()

[Link]()
OUTPUT:

You might also like