-
Notifications
You must be signed in to change notification settings - Fork 47
Add Python Weather App #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
devmalik7
merged 1 commit into
devmalik7:main
from
michalszkil:feature/python-weather-app
Oct 24, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| ## Python Weather App | ||
|
|
||
| A simple weather application built with Python's Tkinter library that fetches and displays current weather information for a specified city using the OpenWeatherMap API. The app also shows a static map of the city's location using the StaticMap library. | ||
|
|
||
| ### Features | ||
| - Fetches current weather data including temperature, humidity, and weather conditions. | ||
| - Displays a static map of the city using the StaticMap library. | ||
| - User-friendly GUI built with Tkinter. | ||
|
|
||
| ### How to Run | ||
| 1. Clone the repository | ||
| 2. Install the required packages: | ||
| ``` | ||
| pip install -r requirements.txt | ||
| ``` | ||
| 3. Replace `OPENWEATHER_API_KEY` in `weather_app.py` with your actual OpenWeatherMap API key. | ||
| 4. Run the application: | ||
| ``` | ||
| python weather_app.py | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Pillow | ||
| requests | ||
| staticmap | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import tkinter as tk | ||
| from tkinter import messagebox | ||
| from PIL import Image, ImageTk | ||
| import requests | ||
| from io import BytesIO | ||
| from staticmap import StaticMap, CircleMarker | ||
|
|
||
| def get_weather() -> None: | ||
| """ | ||
| Fetch weather data for the specified city and update the UI with weather info and map. | ||
| Arguments: | ||
| None | ||
| Returns: | ||
| None | ||
| """ | ||
| city = city_entry.get() | ||
| if not city: | ||
| messagebox.showwarning("Input Error", "Please enter a city name") | ||
| return | ||
|
|
||
| api_key = "OPENWEATHER_API_KEY" # Replace with your OpenWeatherMap API key | ||
| weather_url = "http://api.openweathermap.org/data/2.5/weather" | ||
| params = {"q": city, "appid": api_key, "units": "metric"} | ||
|
|
||
| try: | ||
| response = requests.get(weather_url, params=params) # Fetch weather data | ||
| data = response.json() | ||
| if data["cod"] != 200: | ||
| messagebox.showerror("Error", f"City not found: {city}") | ||
| return | ||
|
|
||
| city_name = data["name"] | ||
| country = data["sys"]["country"] | ||
| temp = data["main"]["temp"] | ||
| weather_desc = data["weather"][0]["description"] | ||
| humidity = data["main"]["humidity"] | ||
| lat = data["coord"]["lat"] | ||
| lon = data["coord"]["lon"] | ||
|
|
||
| weather_info = ( | ||
| f"City: {city_name}, {country}\n" | ||
| f"Temperature: {temp}°C\n" | ||
| f"Weather: {weather_desc.title()}\n" | ||
| f"Humidity: {humidity}%" | ||
| ) | ||
| weather_label.config(text=weather_info) | ||
|
|
||
| # Generate static map locally using OSM tiles | ||
| m = StaticMap(450, 300, url_template='https://tile.openstreetmap.org/{z}/{x}/{y}.png') | ||
| marker = CircleMarker((lon, lat), 'red', 12) | ||
| m.add_marker(marker) | ||
| image = m.render(zoom=10) | ||
|
|
||
| # Convert to Tkinter image | ||
| img_bytes = BytesIO() | ||
| image.save(img_bytes, format='PNG') | ||
| img_bytes.seek(0) | ||
| map_photo = ImageTk.PhotoImage(Image.open(img_bytes)) | ||
|
|
||
| map_label.config(image=map_photo) | ||
| map_label.image = map_photo | ||
|
|
||
| except Exception as e: | ||
| messagebox.showerror("Error", f"Something went wrong:\n{e}") | ||
|
|
||
| # Tkinter UI setup | ||
| root = tk.Tk() | ||
| root.title("Weather App with Local Map") | ||
| root.geometry("500x600") | ||
| root.resizable(False, False) | ||
|
|
||
| # UI Components | ||
| tk.Label(root, text="Enter City Name:", font=("Arial", 14)).pack(pady=10) | ||
| city_entry = tk.Entry(root, font=("Arial", 14)) | ||
| city_entry.pack(pady=5) | ||
|
|
||
| tk.Button(root, text="Get Weather", font=("Arial", 14), command=get_weather).pack(pady=10) | ||
| weather_label = tk.Label(root, text="", font=("Arial", 12), justify="left") | ||
| weather_label.pack(pady=10) | ||
| map_label = tk.Label(root) | ||
| map_label.pack(pady=10) | ||
|
|
||
| root.mainloop() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hr5uu9