Skip to content

Commit ffc88c2

Browse files
Merge pull request avinashkranjan#394 from Aayush-hub/master
Added Distance Calculator GUI
2 parents 2763bc3 + ad08a85 commit ffc88c2

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

Distance-Calculator-GUI/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Distance Calculating App
2+
This app calculates distance between two geo-locations.
3+
4+
# Quick Start:
5+
- Clone this repository.
6+
7+
git clone https://github.com/avinashkranjan/Amazing-Python-Scripts.git
8+
9+
- Change Directory
10+
11+
cd .\Distance-Calculator-GUI\
12+
13+
- Install requirememnts
14+
15+
pip install requirements.txt
16+
17+
- Run python file
18+
19+
python main.py
20+
21+
# Screenshot
22+
23+
![](screenshot/capp.png)
24+
25+
# Author
26+
[Aayush Garg](https://github.com/Aayush-hub)

Distance-Calculator-GUI/main.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from tkinter import *
2+
from geopy.geocoders import Nominatim
3+
from geopy import distance
4+
5+
# user defined funtion
6+
def get_dis():
7+
try:
8+
9+
geolocator = Nominatim(user_agent="geoapiExercises")
10+
11+
place1 = geolocator.geocode(str(e1.get()))
12+
place2 = geolocator.geocode(str(e2.get()))
13+
14+
15+
Loc1_lat,Loc1_lon = (place1.latitude),(place1.longitude)
16+
Loc2_lat,Loc2_lon = (place2.latitude),(place2.longitude)
17+
18+
location1=(Loc1_lat,Loc1_lon)
19+
location2=(Loc2_lat,Loc2_lon)
20+
21+
res = (str(distance.distance(location1, location2).km)+" Km")
22+
23+
result.set(res)
24+
except:
25+
result.set("someting went wrong")
26+
27+
# object of tkinter
28+
# with background set to light grey
29+
master = Tk()
30+
master.configure(bg='light grey')
31+
master.title("Distance Calculating App")
32+
33+
# Variable Classes in tkinter
34+
result = StringVar()
35+
36+
37+
# Creating label for each information
38+
# name using widget Label
39+
Label(master, text="Enter first place : " , bg = "light grey").grid(row=1, sticky=W)
40+
Label(master, text="Enter secound place : " , bg = "light grey").grid(row=2, sticky=W)
41+
42+
Label(master, text="Result :", bg = "light grey").grid(row=3, sticky=W)
43+
44+
# Creating label for class variable
45+
# name using widget Entry
46+
Label(master, text="", textvariable=result,bg = "light grey").grid(row=3,column=1, sticky=W)
47+
48+
49+
e1 = Entry(master,width = 50)
50+
e1.grid(row=1, column=1)
51+
e2 = Entry(master,width = 50)
52+
e2.grid(row=2, column=1)
53+
54+
# creating a button using the widget
55+
b = Button(master, text="Check", command=get_dis, bg = "white")
56+
b.grid(row=1, column=2,columnspan=2, rowspan=2,padx=5, pady=5,)
57+
58+
mainloop()
48 Bytes
Binary file not shown.
17.6 KB
Loading

0 commit comments

Comments
 (0)