from tkinter import *
root = Tk()
root.geometry("700x500")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Simulador de Preço da Gasolina")
# Título
titulo = Label(
text="Simulador de Preço da Gasolina",
font=("Arial", 28, "bold"),
bg="#103030",
fg="#49e3e3"
)
titulo.place(relx=0.08, rely=0.05)
# Textos
texto_sub1 = Label(
text="Preço do barril (€):",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub1.place(relx=0.35, rely=0.25)
texto_sub2 = Label(
text="Custos (refinação + distribuição) €/L:",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub2.place(relx=0.05, rely=0.4)
texto_sub3 = Label(
text="Impostos €/L:",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub3.place(relx=0.43, rely=0.53)
# Entradas
Preço_barril = StringVar()
Preço_barril_entrada = Entry(
textvariable=Preço_barril,
font=("Arial", 12, "bold"),
bg="white",
fg="blue",
justify='center'
)
Preço_barril_entrada.place(relx=0.68, rely=0.26, relwidth=0.3)
Preço_barril_entrada.focus()
Custos_refinação_distribuição = StringVar()
Custos_entrada = Entry(
textvariable=Custos_refinação_distribuição,
font=("Arial", 12, "bold"),
bg="white",
fg="blue",
justify='center'
)
Custos_entrada.place(relx=0.68, rely=0.41, relwidth=0.3)
Impostos = StringVar()
Impostos_entrada = Entry(
textvariable=Impostos,
font=("Arial", 12, "bold"),
bg="white",
fg="blue",
justify='center'
)
Impostos_entrada.place(relx=0.68, rely=0.53, relwidth=0.3)
# Funções
def limpar():
Impostos_entrada.delete(0, END)
Custos_entrada.delete(0, END)
Preço_barril_entrada.delete(0, END)
resultado_texto.config(text="")
def app():
try:
imposto = float(Impostos.get())
custos = float(Custos_refinação_distribuição.get())
preco_barril = float(Preço_barril.get())
preco_litro = (preco_barril / 159) + custos + imposto
if preco_litro < 1.5:
ava = "Preço baixo"
elif preco_litro < 2:
ava = "Preço normal"
else:
ava = "Preço alto"
mensagem = f"Preço estimado: {preco_litro:.2f} €/L\n{ava}"
resultado_texto.config(text=mensagem)
except ValueError:
resultado_texto.config(text="Por favor, insira valores numéricos válidos.")
# 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()