The Wayback Machine - https://web.archive.org/web/20240817083553/https://www.geeksforgeeks.org/create-a-gui-for-weather-forecast-using-openweathermap-api-in-python/
Open In App

Create a GUI for Weather Forecast using openweathermap API in Python

Last Updated : 14 Feb, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Prerequisites: Find current weather of any city using openweathermap API

The idea of this article is to provide a simple GUI application to users to get the current temperature of any city they wish to see. The system also provides a simple user interface for simplification of application. It also provides an amazing UX for its users. The features of this application will be that this will be a real-time weather forecast app that returns the current temperature, maximum and minimum temperature, humidity, latitude, and longitude coordinates of the searched city, current date, and time. It can also change its theme according to the time of day.

Openweathermap API

openweathermap is a service that provides weather data, including current weather data, forecasts, and historical data to the developers of web services and mobile applications.

Modules Needed

  • Tkinter: It is the fastest and easiest way to create GUI applications. This is included in the Python standard modules so there is no need to install it externally.
  • PIL: PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities.
  • json: This module is used to handle JSON files and comes built in with Python. So there is no need to install it externally
  • requests: It is used for making HTTP requests to a specified URL. This module does not comes built in with Python. To install it type the below command in the terminal.
pip install requests

Images Used in the below application:

moon.png

sun.png

logo.png

Below is the implementation.

Python3




# python3 -- Weather Application using API
 
# importing the libraries
from tkinter import *
import requests
import json
import datetime
from PIL import ImageTk, Image
 
 
# necessary details
root = Tk()
root.title("Weather App")
root.geometry("450x700")
root['background'] = "white"
 
# Image
new = ImageTk.PhotoImage(Image.open('logo.png'))
panel = Label(root, image=new)
panel.place(x=0, y=520)
 
 
# Dates
dt = datetime.datetime.now()
date = Label(root, text=dt.strftime('%A--'), bg='white', font=("bold", 15))
date.place(x=5, y=130)
month = Label(root, text=dt.strftime('%m %B'), bg='white', font=("bold", 15))
month.place(x=100, y=130)
 
# Time
hour = Label(root, text=dt.strftime('%I : %M %p'),
             bg='white', font=("bold", 15))
hour.place(x=10, y=160)
 
# Theme for the respective time the application is used
if int((dt.strftime('%I'))) >= 8 & int((dt.strftime('%I'))) <= 5:
    img = ImageTk.PhotoImage(Image.open('moon.png'))
    panel = Label(root, image=img)
    panel.place(x=210, y=200)
else:
    img = ImageTk.PhotoImage(Image.open('sun.png'))
    panel = Label(root, image=img)
    panel.place(x=210, y=200)
 
 
# City Search
city_name = StringVar()
city_entry = Entry(root, textvariable=city_name, width=45)
city_entry.grid(row=1, column=0, ipady=10, stick=W+E+N+S)
 
 
def city_name():
 
    # API Call
    api_request = requests.get("https://api.openweathermap.org/data/2.5/weather?q="
                               + city_entry.get() + "&units;=metric&appid;="+api_key)
 
    api = json.loads(api_request.content)
 
    # Temperatures
    y = api['main']
    current_temprature = y['temp']
    humidity = y['humidity']
    tempmin = y['temp_min']
    tempmax = y['temp_max']
 
    # Coordinates
    x = api['coord']
    longtitude = x['lon']
    latitude = x['lat']
 
    # Country
    z = api['sys']
    country = z['country']
    citi = api['name']
 
    # Adding the received info into the screen
    lable_temp.configure(text=current_temprature)
    lable_humidity.configure(text=humidity)
    max_temp.configure(text=tempmax)
    min_temp.configure(text=tempmin)
    lable_lon.configure(text=longtitude)
    lable_lat.configure(text=latitude)
    lable_country.configure(text=country)
    lable_citi.configure(text=citi)
 
 
# Search Bar and Button
city_nameButton = Button(root, text="Search", command=city_name)
city_nameButton.grid(row=1, column=1, padx=5, stick=W+E+N+S)
 
 
# Country  Names and Coordinates
lable_citi = Label(root, text="...", width=0,
                   bg='white', font=("bold", 15))
lable_citi.place(x=10, y=63)
 
lable_country = Label(root, text="...", width=0,
                      bg='white', font=("bold", 15))
lable_country.place(x=135, y=63)
 
lable_lon = Label(root, text="...", width=0,
                  bg='white', font=("Helvetica", 15))
lable_lon.place(x=25, y=95)
lable_lat = Label(root, text="...", width=0,
                  bg='white', font=("Helvetica", 15))
lable_lat.place(x=95, y=95)
 
# Current Temperature
 
lable_temp = Label(root, text="...", width=0, bg='white',
                   font=("Helvetica", 110), fg='black')
lable_temp.place(x=18, y=220)
 
# Other temperature details
 
humi = Label(root, text="Humidity: ", width=0,
             bg='white', font=("bold", 15))
humi.place(x=3, y=400)
 
lable_humidity = Label(root, text="...", width=0,
                       bg='white', font=("bold", 15))
lable_humidity.place(x=107, y=400)
 
 
maxi = Label(root, text="Max. Temp.: ", width=0,
             bg='white', font=("bold", 15))
maxi.place(x=3, y=430)
 
max_temp = Label(root, text="...", width=0,
                 bg='white', font=("bold", 15))
max_temp.place(x=128, y=430)
 
 
mini = Label(root, text="Min. Temp.: ", width=0,
             bg='white', font=("bold", 15))
mini.place(x=3, y=460)
 
min_temp = Label(root, text="...", width=0,
                 bg='white', font=("bold", 15))
min_temp.place(x=128, y=460)
 
 
# Note
note = Label(root, text="All temperatures in degree celsius",
             bg='white', font=("italic", 10))
note.place(x=95, y=495)
 
 
root.mainloop()


Output:

You can follow the Weather Forecast Project to create your own weather application using Weather API.



Previous Article
Next Article

Similar Reads

Find current weather of any city using OpenWeatherMap API in Python
The OpenWeatherMap is a service that provides weather data, including current weather data, forecasts, and historical data to the developers of web services and mobile applications. It provides an API with JSON, XML, and HTML endpoints and a limited free usage tier. Making more than 60 calls per minute requires a paid subscription starting at USD 4
4 min read
Create a Weather App with Forecast using React-Native
React-Native is an open-source framework used to develop cross-platform applications i.e., you can write code in React-Native and publish it as an Android or IOS app. In this article, we will build a weather app using React-Native. The app contains two features: Getting the current weather of a given city Getting the weather forecast for the next f
5 min read
Create a Real-Time Weather Forecast App with React
Real-time weather forecast app with React involves integrating with a weather API to fetch weather data and display it in the UI. Individuals can use the app to check the current weather conditions, temperature, humidity, and other relevant weather data for their location or any city they are interested in. It helps them plan outdoor activities, cl
5 min read
Implementing Weather Forecast using Facade Design Pattern in Python
Facade Design Patterns are design patterns in Python that provide a simple interface to a complex subsystem. When we look into the world around us, we can always find facade design patterns. An automobile is the best example: you don't need to understand how the engine functions. To operate the engine, you are provided with a set of simple interfac
3 min read
Weather Forecast App using MERN Stack
This project is a simple weather application built using React.js for the frontend and Node.js with Express.js for the backend. It allows users to check the current weather and forecast for a specific city. The backend retrieves weather data from the OpenWeatherMap API and stores it in a MongoDB database. The frontend displays the weather informati
7 min read
Weather Union API(Zamato) with Python
Weather Union provides powerful APIs for integrating live weather data into your applications. With a wide range of endpoints, you can access current weather data at specific locations. This guide will walk you through the various APIs offered by Weather Union and provide examples of how to use them in Python. What is Weather Union &amp; Its Featur
3 min read
GUI to get views, likes, and title of a YouTube video using YouTube API in Python
Prerequisite: YouTube API, Tkinter Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter is the fastest and easiest way to create GUI applications. In this art
2 min read
Create a Weather app using Flask | Python
Prerequisite : Flask installation Flask is a lightweight framework written in Python. It is lightweight because it does not require particular tools or libraries and allow rapid web development. today we will create a weather app using flask as a web framework. this weather web app will provide current weather updates of cities searched. Basic setu
2 min read
Create a Simple Weather App UI using Tailwind CSS
Tailwind CSS helps build simple weather app interfaces with its easy styling and responsive features. Developers use Tailwind CSS to enhance user experience in weather apps, adding functionality and engagement. ApproachCreate a basic HTML structure and then link the Tailwind CSS CDN link.Then apply Tailwind CSS utility classes to style the UI compo
3 min read
Python | Create a GUI Marksheet using Tkinter
Create a python GUI mark sheet. Where credits of each subject are given, enter the grades obtained in each subject and click on Submit. The credits per subject, the total credits as well as the SGPA are displayed after being calculated automatically. Use Tkinter to create the GUI interface. Refer the below articles to get the idea about basics of t
8 min read
Create a GUI to convert CSV file into excel file using Python
Prerequisites: Python GUI – tkinter, Read csv using pandas CSV file is a Comma Separated Value file that uses a comma to separate values. It is basically used for exchanging data between different applications. In this, individual rows are separated by a newline. Fields of data in each row are delimited with a comma. Modules Needed Pandas: Python i
3 min read
Create GUI for Downloading Youtube Video using Python
Prerequisites: Python GUI – tkinter YouTube is a very popular video-sharing website. Downloading a video's/playlist from YouTube is a tedious task. Downloading that video through Downloader or trying to download it from a random website increase's the risk of licking your personal data. Using the Python Tkinter package, this task is very simple-eff
12 min read
Create Copy-Move GUI using Tkinter in Python
Everyone reading this post is well aware of the importance of Copying the file or moving the file from one specific location to another. In this post, we have tried to explain not only the program but added some exciting pieces of Interface. Up to now, many of you may get about what we are talking about. Yes, you are right, We are going to use "Tki
4 min read
Create a GUI to get Sunset and Sunrise time using Python.
Prerequisite: Tkinter module In this article, we are going to write python scripts to get sunset and sunrise time and bind it with the GUI application. Before starting we need to understand suntime and geopy module Modules Needed: suntime module: This module will return the sunset and sunrise time calculation python library. Run this command in you
3 min read
Create a GUI to Extract information from VIN number Using Python
Prerequisite: Python GUI – tkinter In this article, we are going to look at how can we use Python to extract vehicle information from its VIN number (Vehicle Identification Number). A VIN consists of 17 characters (digits and capital letters) that act as a unique identifier for the vehicle. It is a unique code that is assigned to every motor vehicl
3 min read
Create a GUI to search bank information with IFSC Code using Python
Prerequisite: Python GUI – tkinter The following program depicts how a GUI application can be formulated using python script to get bank details by using IFSC code. Here, we are using Razorpay IFSC Toolkit to fetch IFSC code. Razorpay IFSC Toolkit processes IFSC codes via their toolkit and return data set. Module Needed: requests Requests allows yo
3 min read
Create a GUI to find the IP for Domain names using Python
Prerequisite: Python GUI – tkinter In this article, we are going to see how to find IP from Domain Names and bind it with GUI Application using Python. We will use iplookup module for looking up IP from Domain Names. It is a small module which accepts a single domain as a string, or multiple domains as a list, and returns a list of associated IP. R
2 min read
Create First GUI Application using Python-Tkinter
We are now stepping into making applications with graphical elements, we will learn how to make cool apps and focus more on its GUI(Graphical User Interface) using Tkinter. What is Tkinter?Tkinter is a Python Package for creating GUI applications. Python has a lot of GUI frameworks, but Tkinter is the only framework that’s built into the Python sta
10 min read
Create a GUI to extract Lyrics from song Using Python
In this article, we are going to write a python script to extract lyrics from the song and bind with its GUI application. We will use lyrics-extractor to get lyrics of a song just by passing in the song name, it extracts and returns the song's title and song lyrics from various websites. Before starting, install the lyrics-extractor module. Run thi
3 min read
Create a Weather Monitoring Dashboard with Next.js
This project involves building a Weather Monitoring Dashboard using NextJS. The dashboard allows users to check the current weather and forecast for a specific city, as well as an hourly forecast for the next few hours and a daily forecast for the next four days. Output Preview: Let us have a look at how the final output will look like. Prerequisit
6 min read
Create a Weather App in HTML Bootstrap & JavaScript
A weather app contains a user input field for the user, which takes the input of the city name. Once the user enters the city name and clicks on the button, then the API Request is been sent to the OpenWeatherMap and the response is been retrieved in the application which consists of weather, wind speed, description, humidity, pressure etc. Preview
3 min read
Python | Real time weather detection using Tkinter
Prerequisites : Introduction to tkinter | Find current weather of any cityPython offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter outputs the fastest and easiest
5 min read
Weather app using Django | Python
In this tutorial, we will learn how to create a Weather app that uses Django as backend. Django provides a Python Web framework based web framework that allows rapid development and clean, pragmatic design. Basic Setup - Change directory to weather – cd weather Start the server - python manage.py runserver To check whether the server is running or
2 min read
Scraping Weather prediction Data using Python and BS4
This article revolves around scraping weather prediction d data using python and bs4 library. Let's checkout components used in the script - BeautifulSoup- It is a powerful Python library for pulling out data from HTML/XML files. It creates a parse tree for parsed pages that can be used to extract data from HTML/XML files. Requests - It is a Python
3 min read
Get Live Weather Desktop Notifications Using Python
We know weather updates are how much important in our day-to-day life. So, We are introducing the logic and script with some easiest way to understand for everyone. Let’s see a simple Python script to show the live update for Weather information. Modules Needed In this script, we are using some libraries bs4: Beautiful Soup(bs4) is a Python library
2 min read
Weather App in Python using Tkinter module
In this article, we are going to discuss how to create a weather app using tkinter. The GUI app will tell us the current weather of a particular city along with temperature details along with other details. Modules required:Tkinter: It is a built-in python library for making GUI using tkinter toolkit.Requests: It is a library which helps in fetchin
4 min read
Scraping weather data using Python to get umbrella reminder on email
In this article, we are going to see how to scrape weather data using Python and get reminders on email. If the weather condition is rainy or cloudy this program will send you an "umbrella reminder" to your email reminding you to pack an umbrella before leaving the house. We will scrape the weather information from Google using bs4 and requests lib
5 min read
Building A Weather CLI Using Python
Trying to know the weather is something that we all do, every day. But have you ever dreamed of making a tool on your own that can do the same? If yes, then this article is for you. In this article, we will look at a step-by-step guide on how to build a Weather CLI using OpenWeather API. What is OpenWeather API?OpenWeather API is a weather API prov
4 min read
Create a GUI to check Domain Availability using Tkinter
There might be a case where a user wants to create a website and having certain ideas for the website's name but is struck on their availability. So let's develop a GUI that will check for domain availability. We will use the Python-whois module to get information about the website. It's able to extract data for all the popular TLDs (com, org, net,
2 min read
Create a GUI to Get Domain Information Using Tkinter
Prerequisites: Python GUI – tkinter Domain information is very important for every user. It contains information like Name, organization, State, city, Ip address, emails, server name, etc. In this article, we will write code for getting domain information and bind it with GUI Application. We will use the Python-whois module to get information about
2 min read
Practice Tags :
three90RightbarBannerImg