A desktop application that fetches and displays real-time weather data for any city worldwide
The Weather App is a Python application built with Tkinter that retrieves and displays current weather conditions for any city using the OpenWeatherMap API. It provides a simple graphical interface where users can enter a city name and instantly see temperature, humidity, wind speed, and weather conditions.
This project was developed to demonstrate API integration with Python GUI applications. It handles various edge cases including invalid city names, network errors, and API limitations while providing a clean, responsive interface.
The application includes comprehensive error handling, responsive UI elements, and clear display of weather data with appropriate icons representing different weather conditions.
Fetches current weather conditions including temperature, humidity, wind speed, and weather description for any city worldwide.
Utilizes the OpenWeatherMap API to provide accurate and up-to-date weather information with proper error handling.
Built with Tkinter for a clean, intuitive interface that works across Windows, macOS, and Linux.
Gracefully handles invalid inputs, API errors, and network issues with user-friendly error messages.
Sunny
pip install requests)# Clone the repository
git clone api_weather.pygit clone https://github.com/mikeCodeCraft/Python_Mini_Projects.git
# Install dependencies
pip install requests
# Run the application (replace YOUR_API_KEY with actual key)
python weather_app.py
# OpenWeatherMap API Key
API_KEY = "your_api_key_here" # Replace with your actual API key
def get_weather():
city = city_entry.get()
if not city:
messagebox.showwarning("No City", "Please enter a city name.")
return
try:
# Make API request
url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={API_KEY}&units=metric"
response = requests.get(url).json()
# Check for valid response
if response.get("main"):
temp = response["main"]["temp"]
weather = response["weather"][0]["description"].title()
humidity = response["main"]["humidity"]
wind_speed = response["wind"]["speed"]
# Update UI with weather data
result_label.config(
text=f"Temperature in {city.title()}: {temp}°C\n"
f"Condition: {weather}\n"
f"Humidity: {humidity}%\n"
f"Wind Speed: {wind_speed} km/h"
)
else:
message = response.get("message", "Unknown error.")
messagebox.showerror("Error", f"Failed to get weather: {message.capitalize()}")
except requests.exceptions.RequestException as e:
messagebox.showerror("Network Error", f"Failed to connect: {e}")
# Create GUI window
root = tk.Tk()
root.title("Weather App")
root.geometry("300x200")
root.resizable(False, False) # Disable resizing
# City input
city_entry = tk.Entry(root, font=("Arial", 14))
city_entry.pack(pady=10)
# Search button
search_button = tk.Button(root, text="Get Weather", command=get_weather)
search_button.pack()
# Result label
result_label = tk.Label(root, text="", font=("Arial", 12),
wraplength=280, justify="center")
result_label.pack(pady=20)
# Run the app
root.mainloop()
Completed (Active Maintenance)
Clear sky
Few clouds
Scattered clouds
Shower rain
Rain
Thunderstorm
Snow
Mist
Add 5-day weather forecast functionality
Implement location detection using geolocation
Add temperature unit toggle (Celsius/Fahrenheit)
Create an executable version for easy distribution