Project (Weather Forecast) CSE-A
Project (Weather Forecast) CSE-A
Project (Weather Forecast) CSE-A
“WEATHER FORECAST”
(FETCHING WEATHER)
2024-2025
CERTIFICATE
• B. SANGEETHA 22BH1A0522
• D. DURGA DEVI 22BH1A0557
• G. LAKSHMI 22BH1A0581
• G. NAGESHWARI 22BH1A0584
• K. SINDHUJA 22BH1A05A2
INDEX
Weather forecasts have several important uses across various sectors and
for individual planning. Some key uses include:
SYSTEM REQUIREMENTS
To run this weather forecast application using Python and Tkinter, we need
a system that meets the following requirements:
• Hardware Requirements
• Software Requirements
➢ Operating System
- Windows 10/11, macOS, or a modern Linux distribution (Ubuntu,
Fedora, etc.)
➢ Python Environment
-Python Version: Python 3.7 or higher
• Python Libraries
➢ requests: For making HTTP requests to the weather API.
• Additional Software
➢ Tkinter: Tkinter is included with standard Python installations. No
additional installation is typically needed for Tkinter.
• Project Structure
Here's a simple project structure to organize the files:
Weather _forecast/
│
├── main.py # Main script for the weather forecast application
├── README.md # Project documentation
└── requirements.txt # List of dependencies
➢ requirements.txt Content
Create a requirements.txt file with the following content to easily install
dependencies:
requests
pillow
python main.py
• Usage
1. Replace the `api_key` in the `main.py` file with your actual
OpenWeatherMap API key.
2. Run the application:
python main.py
• License
This project is licensed under the MIT License.
SOURCE CODE:
EXPLANATION:
Importing Necessary Libraries
• This function retrieves the city name from the entry widget.
• It calls get_weather to get the weather data.
• If data is available, it extracts temperature, description, humidity,
wind speed, and icon code from the JSON response.
• It sets these details into the result StringVar.
• It also fetches the weather icon and displays it in the icon_label.
• If no data is found or the city name is empty, it displays an error
message.
Creating the Main Application Window
• Creates a label widget for the header with the specified font and
background color.
• Adds padding around the header for better visual appearance.
• Creates a frame to hold the city label, entry widget, and button.
• Adds the label, entry widget, and button with appropriate styling and
padding.
The graphical user interface (GUI) application for fetching and displaying
weather information. Here’s a step-by-step description of what the
application looks like and how it behaves:
Application Window
• Title: The window title is "Weather Forecast".
• Size: The window size is set to 400x400 pixels.
• Background Color: The background color of the window is light gray
(#d9d9d9).
Header
• Label: A header label at the top of the window displays "Weather
Forecast" in a bold, large font.
• Padding: The header has padding to ensure it is visually separated
from other elements.
Input Frame
• City Label: A label prompting the user to enter the city name.
• City Entry: An entry widget where the user types the name of the city.
• Fetch Button: A button labeled "Fetch Weather" which the user clicks
to retrieve the weather information for the entered city.
Result Frame
• Result Label: A label that displays the weather information fetched
from the API. This includes:
➢ Temperature in degrees Celsius.
➢ Weather description (e.g., "clear sky").
➢ Humidity percentage.
➢ Wind speed in meters per second.
• Icon Label: A label to display the weather icon associated with the
current weather conditions.
Behavior
• Initial State: The application starts with empty input fields and no
weather information displayed.
• Fetching Weather:
➢ The user types the city name in the entry widget.
➢ The user clicks the "Fetch Weather" button.
➢ The application calls the get_weather function to retrieve weather
data from the OpenWeatherMap API.
• Displaying Weather:
➢ If the city name is valid and weather data is retrieved, the
application updates the result label with temperature, description,
humidity, and wind speed.
➢ The weather icon is fetched from the OpenWeatherMap API and
displayed in the icon_label.
• Error Handling:
➢ If the city name is invalid or empty, an error message is displayed.
➢ If the weather data is not found for the entered city, an appropriate
message is displayed in the result label, and the icon is cleared.
CONCLUSION
This project not only highlights the practical applications of Python in real-
world scenarios but also underscores the importance of combining various
libraries and tools to create comprehensive applications. Future
enhancements could include additional features like hourly forecasts,
weather alerts, and customizable themes to further improve user
experience.