from tkinter import *
root = Tk()
root.geometry("700x500")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Calcular o preço estimado de uma corrida de táxi")
titulo = Label(
text="Calcular o preço estimado de uma corrida de táxi",
font=("Arial", 20, "bold"),
bg="#103030",
fg="#49e3e3"
)
titulo.place(relx=0.03, rely=0.05)
texto_sub1 = Label(
text="Distância (em km):",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub1.place(relx=0.15, rely=0.23)
texto_sub2 = Label(
text="Espera (em min):",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub2.place(relx=0.18, rely=0.4)
# Entradas
Distancia = StringVar()
Distancia_entrada = Entry(
textvariable=Distancia,
font=("Arial", 12, "bold"),
bg="white",
fg="blue",
justify='center'
)
Distancia_entrada.place(relx=0.55, rely=0.24, relwidth=0.35)
Distancia_entrada.focus()
espera = StringVar()
espera_entrada = Entry(
textvariable=espera,
font=("Arial", 12, "bold"),
bg="white",
fg="blue",
justify='center'
)
espera_entrada.place(relx=0.55, rely=0.41, relwidth=0.35)
texto_sub3 = Label(
text="Horário:",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub3.place(relx=0.32, rely=0.55)
var = StringVar()
dropDownList = ["Dia", "Noite"]
dropdown = OptionMenu(root, var, *dropDownList)
var.set(dropDownList[0])
dropdown.place(relx=0.55, rely=0.55, relwidth=0.35)
dropdown.config(background='#09A3BA', foreground="#FFFFFF", font=("Arial", 18, "bold"))
dropdown["menu"].config(background='#09A3BA', foreground="#FFFFFF", font=("Arial", 18, "bold"))
def limpar():
Distancia_entrada.delete(0, END)
espera_entrada.delete(0, END)
resultado_texto.config(text="")
def app():
try:
horario = var.get().lower()
d = float(Distancia.get())
tempo_espera_min = float(espera.get())
if horario == "dia":
bandeirada = 3.25
preco_km = 0.47
else:
bandeirada = 3.90
preco_km = 0.56
preco_espera_hora = 14.80
preco_espera = (tempo_espera_min / 60) * preco_espera_hora
total = bandeirada + (d * preco_km) + preco_espera
resultado_texto.config(
text=f" Preço estimado: €{total:.2f}",
bg="#cfe2f3"
)
except ValueError:
resultado_texto.config(
text="Por favor, insira valores numéricos válidos.",
bg="#ffcccc"
)
# Botões
but1 = Button(
text="Calcular",
bd=2,
bg='#107db2',
fg='white',
font=('verdana', 12, 'bold'),
command=app
)
but1.place(relx=0.1, rely=0.65, relwidth=0.25, relheight=0.1)
but_limpar = Button(
text="Limpar",
bd=2,
bg='#107db2',
fg='white',
font=('verdana', 12, 'bold'),
command=limpar
)
but_limpar.place(relx=0.4, rely=0.65, relwidth=0.25, relheight=0.1)
but_sair = Button(
text="Sair",
bd=2,
bg='#107db2',
fg='white',
font=('verdana', 12, 'bold'),
command=root.destroy
)
but_sair.place(relx=0.7, rely=0.65, relwidth=0.25, relheight=0.1)
# Resultado
resultado_texto = Label(
text="",
font=("Arial", 14, "bold"),
bg="#cfe2f3"
)
resultado_texto.place(relx=0.05, rely=0.8, relwidth=0.9, relheight=0.15)
root.mainloop()