from tkinter import *
root = Tk()
root.geometry("700x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Distribuir calorias pelas refeições")
titulo = Label(
text="Distribuir calorias pelas refeições",
font=("Arial", 28, "bold"),
bg="#103030",
fg="#49e3e3"
)
titulo.place(relx=0.08, rely=0.05)
texto_sub1 = Label(
text="Total de calorias por dia:",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub1.place(relx=0.1, rely=0.3)
Total_calorias = StringVar()
Total_calorias_entrada = Entry(
textvariable=Total_calorias,
font=("Arial", 12, "bold"),
bg="white",
fg="blue",
justify='center'
)
Total_calorias_entrada.place(relx=0.55, rely=0.31, relwidth=0.35)
Total_calorias_entrada.focus()
def limpar():
Total_calorias_entrada.delete(0, END)
resultado_texto.config(text="")
def app():
try:
calorias = int(Total_calorias.get())
distribuicao = {
"Pequeno-almoço": 0.25,
"Almoço": 0.35,
"Jantar": 0.30,
"Lanche": 0.10
}
resultado = ""
for refeicao, percentagem in distribuicao.items():
kcal = calorias * percentagem
resultado += f"{refeicao}: {kcal:.2f} kcal\n"
resultado_texto.config(text=resultado)
except ValueError:
resultado_texto.config(text="Por favor, insira um número válido.")
# 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.45, 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.45, 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.45, relwidth=0.25, relheight=0.1)
resultado_texto = Label(
text="",
font=("Arial", 12, "bold"),
bg="#cfe2f3",
justify="left",
anchor="w"
)
resultado_texto.place(relx=0.05, rely=0.65, relwidth=0.9, relheight=0.3)
root.mainloop()