Welcome folks today in this post we will be printing full address
geolocation in tkinter using python. All the full source code of the application is shown below.
Get Started
In order to get started we need to install the following library using pip
command as shown below
pip install geopy
After installing this library make an app.py
file and copy paste the following code
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# importing the modules from geopy.geocoders import Nominatim from tkinter import * from tkinter import messagebox def getinfo(): geolocator = Nominatim(user_agent = "geoapiExercises") place = e.get() place_res.set(place) location = geolocator.geocode(place) res.set(location) # object of tkinter # and background set for light grey master = Tk() master.configure(bg = 'light grey') # variable Classes in tkinter place_res = StringVar(); res = StringVar(); # creating label for each information # name using widget Label Label(master, text = "Enter place :" , bg = "light grey").grid(row = 0, sticky = W) Label(master, text = "Place :" , bg = "light grey").grid(row = 1, sticky = W) Label(master, text = "Country Address :" , bg = "light grey").grid(row = 2, sticky = W) # creating lebel for class variable # name using widget Entry Label(master, text = "", textvariable = place_res, bg = "light grey").grid(row = 1, column = 1, sticky = W) Label(master, text = "", textvariable = res, bg = "light grey").grid(row = 2, 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 = getinfo ) b.grid(row = 0, column = 2, columnspan = 2, rowspan = 2, padx = 5, pady = 5) mainloop() |
Now if you execute the above python
script by typing the below command
python app.py