-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathm2km.py
49 lines (41 loc) · 1.23 KB
/
m2km.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
from ttkbootstrap as ttk
import tkinter as tk
def convert():
try:
mile_input = entry_int.get()
if mile_input < 0:
output_string.set("Please enter a positive number!")
else:
km_output = mile_input * 1.60934
output_string.set(km_output)
except tk.TclError:
output_string.set(
"Enter a number, other characters are not supported!")
# window
window = ttk.Window(themename="darkly")
window.title("Convertor")
# label
label = ttk.Label(master=window, text="Miles to Kilometers",
font="Calibri 24 bold")
label.pack()
# input field
input_frame = ttk.Frame(master=window)
entry_int = tk.DoubleVar()
entry = ttk.Entry(master=input_frame,
textvariable=entry_int)
button = ttk.Button(master=input_frame,
text="Convert",
command=convert)
input_frame.pack(pady=10)
entry.pack(side="left", padx=10)
button.pack(side="right")
# output field
output_string = tk.StringVar()
output_label = ttk.Label(
master=window,
text="Output",
font="Calibri 24 italic",
textvariable=output_string)
output_label.pack(pady=5)
# mainloop
window.mainloop()