from tkinter import *
fatores = {
"Cão": 7, # 1 ano humano ≈ 7 anos de cachorro
"Gato": 6, # 1 ano humano ≈ 6 anos de gato
"Coelho": 8, # 1 ano humano ≈ 8 anos de coelho
"Hamster": 25, # 1 ano humano ≈ 25 anos de hamster
"Cavalo": 3, # 1 ano humano ≈ 3 anos de cavalo
"Tartaruga": 0.5 # 1 ano humano ≈ 0.5 anos de tartaruga
}
root = Tk()
root.geometry("700x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Calculadora de idade para vários animais")
titulo = Label(text="Calculadora de idade para vários animais",
font=("Arial", "23", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.08, rely=0.05)
texto_sub1 = Label(text="Escolha um animal:",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.05, rely=0.25)
texto_sub2 = Label(text="Idade:",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.25, rely=0.4)
Idade = StringVar()
Idade_entrada = Entry(textvariable=Idade,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Idade_entrada.place(relx=0.45, rely=0.41, relwidth=0.35)
Idade_entrada.focus()
var = StringVar()
primeiro = list(fatores.keys())[0]
var.set(primeiro)
dropdown = OptionMenu(root, var, *fatores.keys())
dropdown.place(relx=0.45, rely=0.26, 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():
resultado_texto.config(text="")
def app():
try:
idade = int(Idade.get())
animal = var.get()
if animal in fatores:
idade_convertida = idade * fatores[animal]
resultado_texto.config(
text=f"{idade} anos de {animal} equivalem \na aproximadamente {idade_convertida} anos humanos."
)
except ValueError:
resultado_texto.config(text="⚠️ Por favor, insira um número válido.")
but1 = Button(text="Mostrar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.55, 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.55, 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.55, relwidth=0.25, relheight=0.1)
resultado_texto = Label(text="",
font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.7, relwidth=0.9, relheight=0.25)
root.mainloop()