Mundo em Python

Níveis Sonoros (usando Tkinter)

from tkinter import *
root= Tk()
root.title("Níveis Sonoros")
root.geometry("600x400")
root.resizable(0,0)
root.configure(bg="#cfe2f3")
def app():
a = variavel.get()
if a<=80:
resulatdoresultado["fg"] = "#38761d"
mensagem = "Não há qualquer risco para o ouvido\n, " \
"qualquer que seja \no tempo de exposição."
elif a<=90:
resulatdoresultado["fg"] = "yellow"
mensagem = "Aproximamos-nos da zona nociva\n," \
" mas os riscos limitam-se " \
"a exposições\n de muito longa duração."
elif a <= 115:
resulatdoresultado["fg"] = "red"
mensagem = "O ouvido está em risco.\n " \
"Quanto mais forte o som menor o tempo\n" \
"de exposição é necessário para provocar lesão."
else:
resulatdoresultado["fg"] = "brown"
mensagem = "Os ruídos impulsivos .\n " \
"Provocam imediatamente lesões irreversíveis.\n"
resultado.set(mensagem)
def limpar():
variavel_entrada.delete(0, END)
texto = Label(text="Nível sonoro: ",bg="#cfe2f3",fg="#ba990a",
font=("Arial","12","bold"))
texto.place(relx=0.15,rely=0.15)
variavel = DoubleVar()
variavel_entrada= Entry(textvariable=variavel,font=("Arial","12","bold"),
bg="white",fg="blue",justify='center')
variavel_entrada.place(relx=0.55,rely=0.15,relwidth=0.25)
but1 = Button( text="Ver o nível", bd=2, bg='#107db2', fg='white',
font=('verdana', 10, 'bold'),command=app)
but1.place(relx=0.1, rely=0.4, relwidth=0.3, relheight=0.15) but_limpar = Button( text="Limpar", bd=2, bg='#107db2', fg='white',
font=('verdana', 10, 'bold'),command= limpar)
but_limpar.place(relx=0.55, rely=0.4, relwidth=0.3, relheight=0.15)
resultado = StringVar()
resulatdoresultado =Label(textvariable=resultado,font=("Arial",12,"bold"),bg="#f0f8ff")
resulatdoresultado.place(relx=0.05,rely=0.7,relwidth=0.8)
root.mainloop()

 

0