Mundo em Python

Classificar pH

from tkinter import *

root = Tk()
root.geometry("500x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Classificar pH")
titulo = Label(text="Classificar pH",
font=("Arial", 28, "bold"),
bg="#103030", fg="#49e3e3")
titulo.place(relx=0.25, rely=0.05)
texto_sub1 = Label(text="Valor do pH (0 a 14) :",
font=("Arial", 18, "bold"),
bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.05, rely=0.3)
pH = StringVar()
pH_entrada = Entry(textvariable=pH,
font=("Arial", 12, "bold"),
bg="white", fg="blue", justify='center')
pH_entrada.place(relx=0.55, rely=0.31, relwidth=0.35)
def limpar():
pH_entrada.delete(0, END)
resultado_texto.config(text="", bg="#cfe2f3") def app():
try:
valor_ph = float(pH.get())
if valor_ph < 0 or valor_ph > 14:
resultado_texto.config(text="Valor de pH inválido. Deve estar entre 0 a 14",
bg="#FF00FF", fg="white")
elif valor_ph < 7:
resultado_texto.config(text="Ácido", bg="red", fg="white")
elif valor_ph == 7:
resultado_texto.config(text="Neutro", bg="yellow", fg="black")
else:
resultado_texto.config(text="Básico (ou Alcalino)", bg="green", fg="white")
except ValueError:
resultado_texto.config(text="Valor digitado inválido\nDigite 0 a 14",
bg="#FF00FF", fg="white") 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.7, relwidth=0.9, relheight=0.2)
root.mainloop()
0