72 lines
2.2 KiB
Python
72 lines
2.2 KiB
Python
import tkinter as tk
|
|
|
|
def tk_05():
|
|
"""[ 1 kilometre = 0.6214 miles] & [ 1 mile = 1.6093 kilometres]
|
|
Using these figures, make a program that will allow the user to convert
|
|
between miles and kilometres."""
|
|
def conv_km_to_ml():
|
|
kms = txt_in_box.get()
|
|
if kms != "":
|
|
mls = int(kms) * 0.6214
|
|
txt_conv["text"] = round(mls, 3)
|
|
#txt_in_box.delete(0, 'end')
|
|
lbl_in["text"] = "Kilometros"
|
|
lbl_out["text"] = "Millas"
|
|
txt_in_box.focus()
|
|
|
|
def conv_ml_to_km():
|
|
mls = txt_in_box.get()
|
|
if mls != "":
|
|
mls = int(mls) * 1.6093
|
|
txt_conv["text"] = round(mls, 3)
|
|
lbl_in["text"] = "Millas"
|
|
lbl_out["text"] = "Kilometros"
|
|
txt_in_box.focus()
|
|
|
|
def reset():
|
|
txt_in_box.delete(0, 'end')
|
|
lbl_in["text"] = ""
|
|
lbl_out["text"] = ""
|
|
txt_conv["text"] = ""
|
|
txt_in_box.focus()
|
|
|
|
window = tk.Tk()
|
|
window.title("Conversor Distancias TK")
|
|
window.geometry("320x230")
|
|
|
|
lbl_in = tk.Label(text="")
|
|
lbl_in["justify"] = "left"
|
|
lbl_in.place(x=190, y=25, width=100, height=35)
|
|
|
|
txt_in_box = tk.Entry()
|
|
txt_in_box["justify"] = "center"
|
|
txt_in_box.place(x=40, y=25, width=150, height=35)
|
|
txt_in_box.focus()
|
|
|
|
btn_conv1 = tk.Button(text="Convertir a millas", command=conv_km_to_ml)
|
|
btn_conv1["fg"] = "black"
|
|
btn_conv1["bg"] = "cyan"
|
|
btn_conv1.place(x=40, y=120, width=150, height=35)
|
|
|
|
btn_conv2 = tk.Button(text="Convertir a kilometros", command=conv_ml_to_km)
|
|
btn_conv2["fg"] = "black"
|
|
btn_conv2["bg"] = "cyan"
|
|
btn_conv2.place(x=40, y=160, width=150, height=35)
|
|
|
|
btn_clr = tk.Button(text="Limpiar", command=reset)
|
|
btn_clr["fg"] = "black"
|
|
btn_clr["bg"] = "cyan"
|
|
btn_clr.place(x=200, y=120, width=80, height=75)
|
|
|
|
lbl_out = tk.Label(text="")
|
|
lbl_out["justify"] = "left"
|
|
lbl_out.place(x=190, y=75, width=100, height=35)
|
|
|
|
txt_conv = tk.Message(text=0)
|
|
txt_conv["bg"] = "magenta"
|
|
txt_conv["fg"] = "black"
|
|
txt_conv["width"] = 100
|
|
txt_conv.place(x=40, y=75, width=150, height=35)
|
|
|
|
window.mainloop()
|