from tkinter import *
root = Tk()
root.geometry("400x400")
root.resizable(0, 0)
root.config(bg="#183c57")
root.title("Botão Cores")
titulo = Label(text="Botão Cores",
font=("Arial", "45", "bold"),bg="#183c57",fg="#95c9f0")
titulo.place(relx=0.04, rely=0.05)
texto_sub1 = Label(text="Outras Cores",
font=("Arial", "15", "bold"),bg="#183c57",fg="#95c9f0")
texto_sub1.place(relx=0.33, rely=0.3)
cores = StringVar()
cores_entrada = Entry(textvariable=cores,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
cores_entrada.place(relx=0.3, rely=0.4, relwidth=0.45)
def app():
cor = cores.get()
if cor.startswith("#") and len(cor) == 7:
try:
resultado_texto.config(bg=cor)
except ValueError:
print("Valor hexadecimal inválido.")
else:
print("Por favor, insira uma cor hexadecimal válida no formato '#RRGGBB'.")
def amarelo():
resultado_texto.config(bg="yellow")
def vermelho():
resultado_texto.config(bg="red")
but1 = Button(text="Cores", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.05, rely=0.5, relwidth=0.25, relheight=0.1)
but2 = Button(text="Amarelo", bd=2, bg='yellow', fg='white',
font=('verdana', 12, 'bold'), command=amarelo)
but2.place(relx=0.34, rely=0.5, relwidth=0.25, relheight=0.1)
but2 = Button(text="red", bd=2, bg='red', fg='white',
font=('verdana', 12, 'bold'), command=vermelho)
but2.place(relx=0.65, rely=0.5, relwidth=0.25, relheight=0.1)
resultado = StringVar()
resultado_texto = Label(textvariable=resultado,
font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.75, relwidth=0.9,relheight=0.2)
root.mainloop()