Weather App in Python using Tkinter module Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 10 Likes Like Report 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 fetching the data with the help of URL. It can be installed using the below command:pip install requestsApproach: Firstly, we have to use a weather API for fetching the data from the Open Weather Map website by generating an API key, and then we need to create a configuration file to store the key. And finally using that configuration file in the python script. Steps to generate an API key:Login in the Open Weather MapGo to the API section. Then in the Current Weather Data section click on the Api doc.Now in the API Call section, we have the link of api.openweathermap.org/data/2.5/weather?q={city name}&appid={API key}Click on the API key on the link it will direct to the page from where you can get the key. The generated key looks like this:Steps to create the Configuration file:Create a file named config.ini.Write key name enclosed in closed brackets in it here [gfg].Create a variable key(here key) and paste the key you copied as shown below:Steps to create the Python script:Import modules. Python3 # import required modules from configparser import ConfigParser import requests from tkinter import * from tkinter import messagebox We have to first make the body of the GUI with the help of tkinter. Python3 # create object app = Tk() # add title app.title("Weather App") # adjust window size app.geometry("300x300") # add labels, buttons and text city_text = StringVar() city_entry = Entry(app, textvariable=city_text) city_entry.pack() Search_btn = Button(app, text="Search Weather", width=12, command=search) Search_btn.pack() location_lbl = Label(app, text="Location", font={'bold', 20}) location_lbl.pack() temperature_label = Label(app, text="") temperature_label.pack() weather_l = Label(app, text="") weather_l.pack() app.mainloop() Read the config.ini file and then load the key and URL in the program. Python3 # extract key from the # configuration file config_file = "config.ini" config = ConfigParser() config.read(config_file) api_key = config['gfg']['api'] url = 'http://api.openweathermap.org/data/2.5/weather?q=%7B%7D&appid=%7B%7D' Make a getweather() function to get the weather of a particular location. Python3 # explicit function to get # weather details def getweather(city): result = requests.get(url.format(city, api_key)) if result: json = result.json() city = json['name'] country = json['sys'] temp_kelvin = json['main']['temp'] temp_celsius = temp_kelvin-273.15 weather1 = json['weather'][0]['main'] final = [city, country, temp_kelvin, temp_celsius, weather1] return final else: print("NO Content Found") Search function so that we can get the output weather details. Python3 # explicit function to # search city def search(): city = city_text.get() weather = getweather(city) if weather: location_lbl['text'] = '{} ,{}'.format(weather[0], weather[1]) temperature_label['text'] = str(weather[3])+" Degree Celsius" weather_l['text'] = weather[4] else: messagebox.showerror('Error', "Cannot find {}".format(city)) Below is the complete program: Python3 # import required modules from configparser import ConfigParser import requests from tkinter import * from tkinter import messagebox # extract key from the # configuration file config_file = "config.ini" config = ConfigParser() config.read(config_file) api_key = config['gfg']['api'] url = 'http://api.openweathermap.org/data/2.5/weather?q=%7B%7D&appid=%7B%7D' # explicit function to get # weather details def getweather(city): result = requests.get(url.format(city, api_key)) if result: json = result.json() city = json['name'] country = json['sys'] temp_kelvin = json['main']['temp'] temp_celsius = temp_kelvin-273.15 weather1 = json['weather'][0]['main'] final = [city, country, temp_kelvin, temp_celsius, weather1] return final else: print("NO Content Found") # explicit function to # search city def search(): city = city_text.get() weather = getweather(city) if weather: location_lbl['text'] = '{} ,{}'.format(weather[0], weather[1]) temperature_label['text'] = str(weather[3])+" Degree Celsius" weather_l['text'] = weather[4] else: messagebox.showerror('Error', "Cannot find {}".format(city)) # Driver Code # create object app = Tk() # add title app.title("Weather App") # adjust window size app.geometry("300x300") # add labels, buttons and text city_text = StringVar() city_entry = Entry(app, textvariable=city_text) city_entry.pack() Search_btn = Button(app, text="Search Weather", width=12, command=search) Search_btn.pack() location_lbl = Label(app, text="Location", font={'bold', 20}) location_lbl.pack() temperature_label = Label(app, text="") temperature_label.pack() weather_l = Label(app, text="") weather_l.pack() app.mainloop() Output: Create Quiz How to Build a Weather App in Python? | Python Project Comment A abhisheksrivastaviot18 Follow 10 Improve A abhisheksrivastaviot18 Follow 10 Improve Article Tags : Python Python-tkinter Python Tkinter-exercises Python Tkinter-projects Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like