Skip to content

Commit 0dcf3d4

Browse files
authored
Create weight.py
convert weight in different measurement units
1 parent 6789881 commit 0dcf3d4

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

Weight Converter/weight.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#A simple gui script to convert weight in different measurement units
2+
#Author: Siddhant N.
3+
4+
#modules
5+
import tkinter
6+
from tkinter import Label, StringVar, Entry, Text, Button, END
7+
8+
9+
#initialize window
10+
11+
main = tkinter.Tk()
12+
main.title("WeightTable")
13+
main.resizable(0, 0)
14+
main.configure(bg='#0492C2')
15+
16+
17+
def val_kg():
18+
#kilograms to grams
19+
gram = float(e2_value.get()) * 1000
20+
#kilograms to pound
21+
pound = float(e2_value.get()) * 2.20462
22+
#kilograms to ounce
23+
ounce = float(e2_value.get()) * 35.274
24+
25+
#converted text to text widget
26+
t1.delete("1.0", END)
27+
t1.insert(END, gram)
28+
29+
t2.delete("1.0", END)
30+
t2.insert(END, pound)
31+
32+
t3.delete("1.0", END)
33+
t3.insert(END, ounce)
34+
35+
#label widgets
36+
e1 = Label(main, text="Enter Weight In Kilograms")
37+
e2_value = StringVar()
38+
e2 = Entry(main, textvariable=e2_value)
39+
e3 = Label(main, text="Gram")
40+
e4 = Label(main, text="Pound")
41+
e5 = Label(main, text="Ounce")
42+
43+
#Text Widgets
44+
45+
t1 = Text(main, height=1, width=20)
46+
t2 = Text(main, height=1, width=20)
47+
t3 = Text(main, height=1, width=20)
48+
49+
#Convert Button
50+
convert_btn = Button(main, text='Covert', command=val_kg)
51+
52+
#geometry specifiers; grid method.
53+
54+
e1.grid(row=0, column=0)
55+
e2.grid(row=0, column=1)
56+
e3.grid(row=1, column=0)
57+
e4.grid(row=1, column=1)
58+
e5.grid(row=1, column=2)
59+
t1.grid(row=2, column=0)
60+
t2.grid(row=2, column=1)
61+
t3.grid(row=2, column=2)
62+
convert_btn.grid(row=0, column=2)
63+
64+
#run main
65+
66+
main.mainloop()

0 commit comments

Comments
 (0)