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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109 | from tkinter import *
from tkinter import ttk
root=Tk()
root.title("Values Convertor")
root.geometry('510x255')
root.resizable(False,False)
#Creating Labels
text1=ttk.Label(root,text="TO",font=("Times New Roman",15))
text1.grid(row=1,column=2,padx=30)
text2=ttk.Label(root,text="VALUE 1",font=("Times New Roman",10),background="blue", foreground ="white")
text2.grid(row=1,column=0,padx=5)
text3=ttk.Label(root,text="VALUE 2",font=("Times New Roman",10),background="blue", foreground ="white")
text3.grid(row=1,column=3,padx=5)
#Creating Combo Box
value=ttk.Combobox(root,width=20)
value.grid(row=1,column=1)
value2=ttk.Combobox(root,width=20)
#Assigning Values to Combo Box
value['values'] = ("M","FOOT","KM")
value2['values'] = ("CM","INCH","M")
value2.grid(row=1,column=4)
Ans=Entry(root,font=("Arial",15),justify="right",borderwidth=4)
Ans.grid(columnspan=10,row=2,column=0,pady=20,ipadx=40)
def calculate():
if value.get()=="M" and value2.get()=="CM":
a=float(Ans.get())
Ans.delete(END)
b=a*100
d=str(b)
Ans.delete(0,END)
Ans.insert(0,d+" cm")
elif value.get()=="FOOT" and value2.get()=="INCH":
a=float(Ans.get())
Ans.delete(END)
b=a*12
d=str(b)
Ans.delete(0,END)
Ans.insert(0,d+" inch")
return
elif value.get()=="KM" and value2.get()=="M":
a=float(Ans.get())
Ans.delete(END)
b=a*1000
d=str(b)
Ans.delete(0,END)
Ans.insert(0,d+" m")
return
elif value.get()=="M" and value2.get()=="INCH":
a=float(Ans.get())
Ans.delete(END)
b=a*39.37
d=str(b)
Ans.delete(0,END)
Ans.insert(0,d+" inch")
return
elif value.get()=="FOOT" and value2.get()=="CM":
a=float(Ans.get())
Ans.delete(END)
b=a*30.48
d=str(b)
Ans.delete(0,END)
Ans.insert(0,d+" cm")
return
elif value.get()=="FOOT" and value2.get()=="M":
a=float(Ans.get())
Ans.delete(END)
b=a/3.281
d=str(b)
Ans.delete(0,END)
Ans.insert(0,d+" m")
return
elif value.get()=="KM" and value2.get()=="CM":
a=float(Ans.get())
Ans.delete(END)
b=a*100000
d=str(b)
Ans.delete(0,END)
Ans.insert(0,d+" cm")
return
elif value.get()=="KM" and value2.get()=="INCH":
a=float(Ans.get())
Ans.delete(END)
b=a*39370
d=str(b)
Ans.delete(0,END)
Ans.insert(0,d+" inch")
return
def delete():
Ans.delete(0,END)
cal=Button(root,text="CALCULATE",command=calculate,bg="lightgreen")
cal.grid(row=3,column=0,columnspan=5,ipady=20,ipadx=200)
remo=Button(root,text="ERASE",command=delete,bg="#fa8e70")
remo.grid(row=4,column=0,columnspan=8,pady=20,ipady=20,ipadx=215)
root.mainloop()
|
0 Comments