Mundo em Python

Calculadora de Calorias Queimadas

from tkinter import *

# Dicionário com valores MET
valores_met = {
"Caminhada": 3.5,
"Corrida": 7.0,
"Bicicleta": 6.0,
"Saltar à corda": 10.0
} root = Tk()
root.geometry("700x500")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Calculadora de Calorias Queimadas") titulo = Label(
text="Calculadora de Calorias Queimadas",
font=("Arial", "28", "bold"), bg="#103030", fg="#49e3e3"
)
titulo.place(relx=0.1, rely=0.05, relwidth=0.8) texto_sub1 = Label(
text="Peso (em kg):",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3"
)
texto_sub1.place(relx=0.35, rely=0.35) texto_sub2 = Label(
text="Tempo de exercício (em minutos):",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3"
)
texto_sub2.place(relx=0.05, rely=0.5) texto_sub3 = Label(
text="Exercício:",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3"
)
texto_sub3.place(relx=0.35, rely=0.2) Tempo = StringVar()
Tempo_entrada = Entry(
textvariable=Tempo,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center'
)
Tempo_entrada.place(relx=0.65, rely=0.5, relwidth=0.28) Peso = StringVar()
Peso_entrada = Entry(
textvariable=Peso,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center'
)
Peso_entrada.place(relx=0.65, rely=0.35, relwidth=0.28)
Peso_entrada.focus() var = StringVar()
dropDownList = list(valores_met.keys())
dropdown = OptionMenu(root, var, *dropDownList)
var.set(dropDownList[0])
dropdown.place(relx=0.55, rely=0.2, 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():
Tempo_entrada.delete(0, END)
Peso_entrada.delete(0, END)
resultado_texto.config(text="") def app():
try:
peso = float(Peso.get())
tempo = int(Tempo.get())
v = var.get()
met = valores_met.get(v) if met is None:
resultado_texto.config(text="Exercício inválido.")
return

calorias = met * peso * tempo * 0.0175
plural = "minuto" if tempo == 1 else "minutos"
resultado_texto.config(
text=f"Queimou aproximadamente {calorias:.2f} calorias\n"
f"durante {tempo} {plural} de {v.lower()}."
)
except ValueError:
resultado_texto.config(text="Por favor, digite apenas números válidos para peso e tempo.") 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_texto = Label(
text="", font=("Arial", 12, "bold"), bg="#cfe2f3"
)
resultado_texto.place(relx=0.05, rely=0.8, relwidth=0.9, relheight=0.15) root.mainloop()
0