Python GUI Application

Weather App

A desktop application that fetches and displays real-time weather data for any city worldwide

Project Overview

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.

Key Features

Real-Time Weather Data

Fetches current weather conditions including temperature, humidity, wind speed, and weather description for any city worldwide.

OpenWeatherMap API Integration

Utilizes the OpenWeatherMap API to provide accurate and up-to-date weather information with proper error handling.

User-Friendly GUI

Built with Tkinter for a clean, intuitive interface that works across Windows, macOS, and Linux.

Comprehensive Error Handling

Gracefully handles invalid inputs, API errors, and network issues with user-friendly error messages.

Application Preview

Current Weather

Weather icon
24°C

Sunny

Humidity
65%
Wind Speed
12 km/h

Installation & Usage

Prerequisites

  • Python 3.6 or higher
  • Tkinter (usually included with Python)
  • requests library (pip install requests)
  • OpenWeatherMap API key (free tier available)

Running the Application

# 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

How to Use

  1. Enter your OpenWeatherMap API key in the code
  2. Run the application
  3. Type a city name in the input field
  4. Click "Get Weather" or press Enter
  5. View the current weather conditions for the specified city

Code Highlights

API Key Configuration

# OpenWeatherMap API Key
API_KEY = "your_api_key_here"  # Replace with your actual API key

Weather Data Fetching Function

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}")

GUI Setup

# 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()

Project Details

Status

Completed (Active Maintenance)

Technologies

Python Tkinter requests OpenWeatherMap API

Tags

python gui api weather

Weather Conditions

Clear sky Clear sky
Few clouds Few clouds
Scattered clouds Scattered clouds
Shower rain Shower rain
Rain Rain
Thunderstorm Thunderstorm
Snow Snow
Mist Mist

Future Enhancements

Add 5-day weather forecast functionality

Implement location detection using geolocation

Add temperature unit toggle (Celsius/Fahrenheit)

Create an executable version for easy distribution