-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
56 lines (42 loc) · 1.29 KB
/
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
48
49
50
51
52
53
54
55
56
from tkinter import *
# Creating a GUI Window
window = Tk()
def from_kg():
# convert kg -> gram
gram = float(e2_value.get()) * 1000
# convert kg -> pound
pound = float(e2_value.get()) * 2.20462
# convert kg -> ounce
ounce = float(e2_value.get()) * 35.274
# Enters the converted weight to the text widget
t1.delete('1.0', END)
t1.insert(END, gram)
t2.delete('1.0', END)
t2.insert(END, pound)
t3.delete('1.0', END)
t3.insert(END, ounce)
# create the label widgets
e1 = Label(window, text='Enter the weight in KG(KiloGrams)')
e2_value = StringVar()
e2 = Entry(window, textvariable=e2_value)
e3 = Label(window, text='Gram')
e4 = Label(window, text='Pound')
e5 = Label(window, text='Ounce')
# create the text widgets
t1 = Text(window, height=1, width=20)
t2 = Text(window, height=1, width=21)
t3 = Text(window, height=1, width=22)
# create the button widget
b1 = Button(window, text='Convert', command=from_kg)
# grid method is used for placing the widgets at respective positions in table like structure.
e1.grid(row=0, column=0)
e2.grid(row=0, column=1)
e3.grid(row=1, column=0)
e4.grid(row=1, column=1)
e5.grid(row=1, column=2)
t1.grid(row=2, column=0)
t2.grid(row=2, column=1)
t3.grid(row=2, column=2)
b1.grid(row=0, column=2)
# start the GUI
window.mainloop()