Skip to content
Related Articles
Open in App
Not now

Related Articles

Application to get address details from zip code Using Python

Improve Article
Save Article
  • Last Updated : 20 Apr, 2022
Improve Article
Save Article

Prerequisite: Tkinter

In this article, we are going to write scripts to get address details from a given Zip code or Pincode using tkinter and geopy module in python, Tkinter is the most commonly used GUI module in python to illustrate graphical objects and geopy is a python module to locate the coordinates of addresses, cities, countries, landmarks, and zip code.


The tkinter module is an in-built module in Python, however, we need to install geopy module:

pip install geopy


  1. Import geopy module.
  2. Use Nominatim API to access the corresponding to a set of coordinates, nominatim uses OpenStreetMap data to find locations on Earth by name and address (geocoding).
  3. Use geocode() to get the location of given Zipcode and displaying it.

Below is the implementation of the above approach:


# Importing required module
from geopy.geocoders import Nominatim
# Using Nominatim Api
geolocator = Nominatim(user_agent="geoapiExercises")
# Zipcode input
zipcode = "800011"
# Using geocode()
location = geolocator.geocode(zipcode)
# Displaying address details
print("Details of the Zipcode:")


Zipcode: 800011
Details of the Zipcode:
Danapur, Dinapur-Cum-Khagaul, Patna, Bihar, 800011, India

Below is a GUI implementation of the above program using tkinter module:


# Importing required modules
from geopy.geocoders import Nominatim
from tkinter import *
# Function to get zipcode input
def zip_code():
        geolocator = Nominatim(user_agent="geoapiExercises")
        zipcode = str(e.get())
        location = geolocator.geocode(zipcode)
        location = "Oops! something went wrong"
# Creating tkinter object
# and background set for light grey
master = Tk()
master.configure(bg='light grey')
# Variable Classes in tkinter
res = StringVar();
# Creating label for each information
Label(master, text="Zipcode: " , bg = "light grey").grid(row=0, sticky=W)
Label(master, text="Details of the pincode:", bg = "light grey").grid(row=3, sticky=W)
# Creating label for class variable
Label(master, text="", textvariable=res,bg = "light grey").grid(row=3,column=1, sticky=W)
e = Entry(master)
e.grid(row=0, column=1)
# Creating a button using the widget 
# Button that will call the submit function
b = Button(master, text="Show", command=zip_code )
b.grid(row=0, column=2,columnspan=2, rowspan=2,padx=5, pady=5)
# this code belongs to Satyam kumar (ksatyam858)


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!