-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkgToPound.py
More file actions
54 lines (42 loc) · 1.36 KB
/
Copy pathkgToPound.py
File metadata and controls
54 lines (42 loc) · 1.36 KB
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
import tkinter
from tkinter import ttk
import time
import random
main_window = tkinter.Tk()
main_window.title("kg to pound")
tab = ttk.Notebook(main_window)
main_tab = ttk.Frame(tab)
tab.add(main_tab, text="kg to pound")
lable1 = ttk.Label(main_tab, text="Enter kg:")
lable1.grid(row=0, column=0)
entry = ttk.Entry(main_tab)
entry.grid(row=1, column=0)
label2 = ttk.Label(main_tab, text="result")
label2.grid(row=2, column=0, columnspan=2)
result_label = ttk.Label(main_tab, text="")
result_label.grid(row=3, column=0, columnspan=2)
def convert():
input = entry.get()
if input == "hi" or input == "hello":
result_label.config(text="Hello")
return
elif input == "bye":
main_window.destroy()
return
else:
try:
if random.randint(0, 5) == 0:
result_label.config(text="WTF IS KILLOGRAM 🦅")
return
else:
kg = float(input)
pound = kg * 2.20462
result_label.config(text=f"{pound:.2f} pounds")
return
except ValueError:
result_label.config(text="Value Error")
convert_button = ttk.Button(main_tab, text="Convert", command=convert)
convert_button.grid(row=4, column=0, columnspan=2)
main_window.bind("<Return>", lambda event: convert())
tab.pack(expand=1, fill="both")
main_window.mainloop()