Day 46 Python for Coders ❄️Build a Real-Time Weather App with Python in Minutes! 🌦️☀️#coding

学習

Get ready to code your own Weather App using Python! 🌍 This project uses the OpenWeather API to fetch real-time weather updates for any city. It’s a perfect beginner project to learn API integration, working with JSON data, and building GUIs with Tkinter. Whether you’re a coding enthusiast or just starting out, this project is both fun and practical!

🔑 What You’ll Learn:

How to fetch live weather data using APIs
Parsing JSON responses in Python
Building interactive GUI applications with Tkinter
📜 Source Code:

python
Copy code
import tkinter as tk
import requests

# Function to get weather data
def get_weather():
city = city_entry.get()
api_key = “your_api_key_here” # Get your own API key from OpenWeather
url = f”http://api.openweathermap.org/data/2.5/weather?q=city&appid=api_key&units=metric”
response = requests.get(url)

if response.status_code == 200:
data = response.json()
weather = data[‘weather’][0][‘description’]
temp = data[‘main’][‘temp’]
result_label.config(text=f”Weather: weathernTemperature: temp°C”)
else:
result_label.config(text=”City not found or invalid API key!”)

# Create main window
root = tk.Tk()
root.title(“Weather App”)

# Create widgets
city_entry = tk.Entry(root, font=(“Arial”, 14))
city_entry.pack(pady=10)

get_weather_button = tk.Button(root, text=”Get Weather”, font=(“Arial”, 14), command=get_weather)
get_weather_button.pack(pady=10)

result_label = tk.Label(root, font=(“Arial”, 14), bg=”lightblue”, width=30, height=5)
result_label.pack(pady=20)

root.mainloop()
💡 Enhancements:

Add weather icons for visual appeal.
Display more data like humidity, wind speed, or sunrise/sunset times.
Customize the interface with weather-themed backgrounds.
🌐 Resources:

OpenWeather API: https://openweathermap.org/api
Learn more about Tkinter: https://docs.python.org/3/library/tkinter.html
📢 Trending Hashtags:
#Python #WeatherApp #Tkinter #APIIntegration #LearnPython #PythonProjects #EgniCode #CodeWithPython #ProgrammingBasics #AppDevelopment #TechTutorial #OpenWeatherAPI #PythonCoding #RealTimeData
#greenscreen #ai #mlbb #fannyvideo

コメント

タイトルとURLをコピーしました