-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmile_to_km.py
82 lines (28 loc) · 861 Bytes
/
mile_to_km.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from tkinter import *
# Functionality
def miles_to_km():
miles = float(miles_inpt.get())
km = miles * 1.609
km_output_label.config(text=f'{km}')
# Window setup
window = Tk()
window.title('Miles to Km Converter')
window.config(padx=20, pady=20)
# Miles input widget & label
miles_inpt = Entry(width=7)
miles_inpt.grid(column=1, row=0)
miles_label = Label(text='Miles')
miles_label.grid(column=2, row=0)
# 'is equal' label
is_equal_label = Label(text='is equal to')
is_equal_label.grid(column=0, row=1)
# Km output label
km_output_label = Label(text='0')
km_output_label.grid(column=1, row=1)
# Km label
km_label = Label(text='Km')
km_label.grid(column=2, row=1)
# Calculate button
calculate_btn = Button(text='Calculate', command=miles_to_km)
calculate_btn.grid(column=1, row=2)
window.mainloop()