This repository contains two versions of a Weather App built with Python:
Console-based Weather App
: A command-line interface (CLI) application.GUI-based Weather App
: A graphical user interface (GUI) application using Tkinter.
Both versions fetch and display weather information for a given location using the OpenWeatherMap
API.
- Fetches current weather data for a specified location.
- Displays temperature, humidity, weather description, wind speed, cloudiness, sunrise, and sunset times.
- Simple and user-friendly interface for both CLI and GUI.
Python 3.12
installed on your machine.- An
API key
from OpenWeatherMap. You can get it here.
- Clone the repository or download the code:
git clone https://github.com/m-hammad-faisal/weather-app.git cd weather-app
- Install the required Python packages:
pip install -r requirements.txt
- Make sure you have Tkinter installed. Tkinter is included with the standard Python distribution. If you encounter issues, you can install it via your package manager:
- On Debian-based Linux distributions (like
Ubuntu
):sudo apt-get install python3-tk
- On
macOS
:brew install python-tk
- On Debian-based Linux distributions (like
- Replace
YOUR_API_KEY
in the code with your actual API key from OpenWeatherMap in both the console and GUI versions.
Open cloned repository in terminal and run the script:
python -m weather_app_cli.weather_app
Follow the prompts to enter a location and receive the weather information.
weather_app.py
: The main script for the console application.
Enter a location (or 'exit' to quit): Lahore
Weather in Lahore, PK (Longitude: 74.3436, Latitude: 31.5497):
Weather: Haze
Detail: haze
Temperature: 35.99°C (Feels like: 36.15°C)
Min Temperature: 35.99°C
Max Temperature: 36.72°C
Pressure: 1004 hPa
Humidity: 30%
Visibility: 4000 meters
Cloudiness: 40%
Wind Speed: 4.12 m/s
Wind Direction: 270°
Sunrise: 2024-06-06 04:57:38
Sunset: 2024-06-06 19:05:19
Open cloned repository in terminal and run the script:
python -m weather_app_gui.weather_app
A window will appear prompting you to enter a location. Enter the name of the city or location and click "Get Weather". The weather information will be displayed in the window.
weather_app.py
: The main script that creates and runs the Tkinter GUI.- The GUI is designed and managed within a
WeatherApp
class to avoid the use of global variables and to keep the code organized.
__init__(self, root)
: Initializes the GUI components.get_weather(self)
: Fetches and displays the weather information for the entered location.
fetch_weather(api_key, location)
: Makes an API call to OpenWeatherMap and returns the weather data.format_weather_data(data)
: Formats the fetched weather data for display.
Contributions are welcome! Please fork this repository and submit pull requests for any features or improvements.
This project is licensed under the MIT License
. See the LICENSE file for details.