from tkinter import *
root = Tk()
root.geometry("400x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Classificar Decibeis")
titulo = Label(text="Classificar Decibeis",
font=("Arial", "28", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.05, rely=0.05)
texto_sub1 = Label(text="Nível de Decibel:",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.05, rely=0.32)
Decibel = StringVar()
Decibel_entrada = Entry(textvariable=Decibel,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Decibel_entrada.place(relx=0.6, rely=0.33, relwidth=0.33)
def limpar():
Decibel_entrada.delete(0, END)
resultado_texto.config(text="")
def app():
try:
nivel = int(Decibel.get()) # Obtém o valor da entrada
if nivel < 10:
mensagem = "Imperceptível"
elif 10 <= nivel < 20:
mensagem = "Muito fraco"
elif 20 <= nivel < 40:
mensagem = "Fraco"
elif 40 <= nivel < 60:
mensagem = "Moderado"
elif 60 <= nivel < 80:
mensagem = "Alto"
elif 80 <= nivel < 100:
mensagem = "Muito alto"
elif 100 <= nivel < 120:
mensagem = "Extremamente alto"
elif 120 <= nivel < 140:
mensagem = "Doloroso"
else:
mensagem = "Perigoso (Risco de perda auditiva imediata)"
resultado_texto.config(text=f"Nível {nivel} dB: {mensagem}")
except ValueError:
resultado_texto.config(text="Valor digitado inválido!")
but1 = Button(text="Classificar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.5, 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.5, 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.5, relwidth=0.25, relheight=0.1)
resultado_texto = Label(text="",
font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.65, relwidth=0.9, relheight=0.3)
root.mainloop()