from tkinter import *
root = Tk()
root.geometry("400x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Entrar")
senha = "1234"
titulo = Label(text="Entrar",
font=("Arial", "28", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.18, rely=0.05)
# Texto de entrada
texto_sub1 = Label(text="Entrada:",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.2, rely=0.2)
Entrada = StringVar()
def validar_entrada(text):
return text.isdigit() and len(text) <= 4 # Apenas números e máximo 4 caracteres
vcmd = root.register(validar_entrada) # Registra a validação
Entrada_entrada = Entry(textvariable=Entrada,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center',
validate="key", validatecommand=(vcmd, "%P"),
show="*") # Inicialmente mostra "*"
Entrada_entrada.place(relx=0.47, rely=0.21, relwidth=0.4)
mostrar_senha = False
def alternar_visibilidade():
global mostrar_senha
if mostrar_senha:
Entrada_entrada.config(show="*")
botao_mostrar.config(text=" Mostrar")
else:
Entrada_entrada.config(show="")
botao_mostrar.config(text="Ocultar")
mostrar_senha = not mostrar_senha # Alterna o estado
botao_mostrar = Button(text="Mostrar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=alternar_visibilidade)
botao_mostrar.place(relx=0.4, rely=0.33, relwidth=0.35, relheight=0.1)
def limpar():
Entrada.set("")
resultado_texto.config(text="", fg="black")
def app():
ent = Entrada.get()
if len(ent) != 4:
resultado_texto.config(text="A senha deve ter 4 dígitos!", fg="orange")
elif ent == senha:
resultado_texto.config(text="Acesso Permitido!", fg="green")
else:
resultado_texto.config(text="Senha Incorreta!", fg="red")
but1 = Button(text="Mostrar", 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="#103030", fg="white")
resultado_texto.place(relx=0.05, rely=0.7, relwidth=0.9, relheight=0.15)
root.mainloop()