-
-
Notifications
You must be signed in to change notification settings - Fork 314
/
Copy pathweight.py
66 lines (49 loc) · 1.39 KB
/
weight.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
#A simple gui script to convert weight in different measurement units
#Author: Siddhant N.
#modules
import tkinter
from tkinter import Label, StringVar, Entry, Text, Button, END
#initialize window
main = tkinter.Tk()
main.title("WeightTable")
main.resizable(0, 0)
main.configure(bg='#0492C2')
def val_kg():
#kilograms to grams
gram = float(e2_value.get()) * 1000
#kilograms to pound
pound = float(e2_value.get()) * 2.20462
#kilograms to ounce
ounce = float(e2_value.get()) * 35.274
#converted text to 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)
#label widgets
e1 = Label(main, text="Enter Weight In Kilograms")
e2_value = StringVar()
e2 = Entry(main, textvariable=e2_value)
e3 = Label(main, text="Gram")
e4 = Label(main, text="Pound")
e5 = Label(main, text="Ounce")
#Text Widgets
t1 = Text(main, height=1, width=20)
t2 = Text(main, height=1, width=20)
t3 = Text(main, height=1, width=20)
#Convert Button
convert_btn = Button(main, text='Covert', command=val_kg)
#geometry specifiers; grid method.
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)
convert_btn.grid(row=0, column=2)
#run main
main.mainloop()