Mundo em Python

Exercício por Semana

from tkinter import *

root = Tk()
root.geometry("750x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Exercício por Semana") titulo = Label(
text="Exercício por Semana",
font=("Arial", 28, "bold"),
bg="#103030",
fg="#49e3e3"
)
titulo.place(relx=0.25, rely=0.05) texto_sub1 = Label(
text="Quantas vezes faz exercícios por semana:",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub1.place(relx=0.05, rely=0.25) texto_sub2 = Label(
text="Quantos minutos por sessão (em min):",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub2.place(relx=0.12, rely=0.45) # Entradas
exercicios_por_semana = StringVar()
entrada_semana = Entry(
textvariable=exercicios_por_semana,
font=("Arial", 12, "bold"),
bg="white",
fg="blue",
justify="center"
)
entrada_semana.place(relx=0.73, rely=0.26, relwidth=0.25)
entrada_semana.focus() minutos_por_sessao = StringVar()
entrada_minutos = Entry(
textvariable=minutos_por_sessao,
font=("Arial", 12, "bold"),
bg="white",
fg="blue",
justify="center"
)
entrada_minutos.place(relx=0.73, rely=0.46, relwidth=0.25) # Função limpar
def limpar():
entrada_minutos.delete(0, END)
entrada_semana.delete(0, END)
resultado_texto.config(text="", bg="#cfe2f3") # Função principal
def app():
try:
min = float(minutos_por_sessao.get())
semana = float(exercicios_por_semana.get()) if semana <= 7: total = min * semana if total < 150:
resultado_texto.config(
text=f"Total: {total:.0f} min/semana\nClassificação: Sedentário",
bg="#ff6b6b"
) elif 150 <= total <= 300:
resultado_texto.config(
text=f"Total: {total:.0f} min/semana\nClassificação: Ativo",
bg="#ffd166"
) else:
resultado_texto.config(
text=f"Total: {total:.0f} min/semana\nClassificação: Muito Ativo",
bg="#06d6a0"
) else:
resultado_texto.config(
text="Os dias da semana não podem ser superiores a 7.",
bg="#ff6b6b"
) except ValueError:
resultado_texto.config(
text="Por favor, insira valores numéricos válidos.",
bg="#ff6b6b"
) # 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_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