from tkinter import *
# Janela principal
root = Tk()
root.geometry("500x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Temperatura Quente")
# Título
titulo = Label(
text="Temperatura Quente",
font=("Arial", 28, "bold"),
bg="#103030",
fg="#49e3e3"
)
titulo.place(relx=0.5, rely=0.05, anchor='center')
# Texto do campo de entrada
texto_sub1 = Label(
text="Temperatura (ºC) :",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub1.place(relx=0.05, rely=0.32)
# Entrada de temperatura
Temperatura = StringVar()
Temperatura_entrada = Entry(
textvariable=Temperatura,
font=("Arial", 12, "bold"),
bg="white",
fg="blue",
justify='center'
)
Temperatura_entrada.place(relx=0.5, rely=0.33, relwidth=0.38)
Temperatura_entrada.focus()
# Resultado (rótulo para exibir o nível de risco)
resultado_texto = Label(
text="",
font=("Arial", 12, "bold"),
bg="#cfe2f3",
fg="black"
)
resultado_texto.place(relx=0.05, rely=0.7, relwidth=0.9, relheight=0.25)
# Função para verificar a temperatura
def app():
try:
temp = float(Temperatura.get())
if temp < 34:
resultado_texto.config(bg='green', fg='white')
resultado_texto.config(text=' Sem risco\nTemperaturas dentro do normal')
elif temp < 37:
resultado_texto.config(bg='yellow', fg='black')
resultado_texto.config(text=' Risco moderado\nRecomenda-se precaução')
elif temp < 40:
resultado_texto.config(bg='#FFA500', fg='black') # Laranja
resultado_texto.config(text=' Risco elevado\nEvite exposição ao sol')
else:
resultado_texto.config(bg='red', fg='white')
resultado_texto.config(text=' Risco extremo\nProcure locais frescos e hidrate-se')
except ValueError:
resultado_texto.config(bg='#cfe2f3', fg='red')
resultado_texto.config(text="Valor digitado inválido!")
# Função para limpar os campos
def limpar():
Temperatura_entrada.delete(0, END)
resultado_texto.config(text="", bg="#cfe2f3")
# Botão Verificar
but1 = Button(
text="Verificar",
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)
# Botão Limpar
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)
# Botão Sair
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)
# Iniciar aplicação
root.mainloop()