Skip to content

Commit 5c11707

Browse files
authored
Create weight.py
1 parent 7217456 commit 5c11707

File tree

1 file changed

+65
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)