0% found this document useful (0 votes)
2 views2 pages

Tkinter Weather App with API Integration

Uploaded by

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

Tkinter Weather App with API Integration

Uploaded by

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

import tkinter as tk

import requests
from tkinter import messagebox
from PIL import Image, ImageTk
import ttkbootstrap

def get_weather(city):
API_Key = "abfebb52a1440c586f2d9c1fd3a59973"
url = f"[Link]
q={city}&appid={API_Key}"
res = [Link](url)

if res.status_code == 404:
[Link]("error","city not found")
return None

weather = [Link]()
icon_id = weather ['weather'] [0] ['icon']
temperature = weather ['main'] ['temp'] - 273.15
description = weather['weather'] [0] ['description']
city = weather ['name']
country = weather['sys'] ['country']

icon_url = f"[Link]
return(icon_url, temperature, description, city, country)

def search():
city = city_entry.get()
result = get_weather(city)
if result is None:
return

icon_url, temperature, description, city, country = result


location_label.configure(text=f"{city}, {country}")

image = [Link]([Link](icon_url, stream=True).raw)


icon = [Link](image)
icon_label.configure(image=icon)
icon_label.image = icon

temperature_label.configure(text=f"temperature: {temperature:.2f}°C")
description_label.configure(text=f"description: {description}")

root = [Link](themename="morph")
[Link]("weather app")
[Link]("400x400")

city_entry = [Link](root, font="helvetica, 18")


city_entry.pack(pady=10)

search_button = [Link](root, text="search", command=search,


bootstyle="warning" )
search_button.pack(pady=10)

location_label = [Link](root, font="helvetica, 25")


location_label.pack(pady=20)

icon_label = [Link](root)
icon_label.pack()

temperature_label = [Link](root, font="helvetica, 20")


temperature_label.pack()

description_label = [Link](root, font="helvetica, 25")

You might also like