Mundo em Python

Gerador de Senha Wi-Fi

from tkinter import *
import string
import secrets root = Tk()
root.geometry("700x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Gerador de Senha Wi-Fi")
titulo = Label(
root,
text="Gerador de Senha Wi-Fi",
font=("Arial", 28, "bold"),
bg="#103030",
fg="#49e3e3"
)
titulo.place(relx=0.18, rely=0.05) texto_sub1 = Label(
root,
text="Tamanho da senha (mínimo 8):",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub1.place(relx=0.05, rely=0.25) Tamanho_senha = StringVar() Tamanho_senha_entrada = Entry(
root,
textvariable=Tamanho_senha,
font=("Arial", 12, "bold"),
bg="white",
fg="blue",
justify='center'
)
Tamanho_senha_entrada.place(relx=0.6, rely=0.26, relwidth=0.3)
Tamanho_senha_entrada.focus() v = StringVar(value="s") Label(
root,
text="Usar símbolos?",
font=("Arial", 15, "bold"),
bg="#103030",
fg="#49e3e3"
).place(relx=0.3, rely=0.41) Radiobutton(root, text="Sim", variable=v, value="s",
bg="#103030", fg="black", selectcolor="white",font=('verdana', 15, 'bold')).place(relx=0.55, rely=0.4) Radiobutton(root, text="Não", variable=v, value="n",
bg="#103030", fg="black", selectcolor="white",font=('verdana', 15, 'bold')).place(relx=0.7, rely=0.4) def limpar():
Tamanho_senha_entrada.delete(0, END)
resultado_texto.config(text="") def gerar_senha():
try:
n = int(Tamanho_senha.get()) if n < 8:
n = 8
resultado_texto.config(text="Senha muito curta! Usando tamanho 8.")
return

caracteres = string.ascii_letters + string.digits if v.get() == "s":
caracteres += string.punctuation senha = ''.join(secrets.choice(caracteres) for _ in range(n)) resultado_texto.config(text=senha) except ValueError:
resultado_texto.config(text="Por favor, insira um número válido.") def copiar_senha():
senha = resultado_texto.cget("text")
if senha:
root.clipboard_clear()
root.clipboard_append(senha)
resultado_texto.config(text=f"{senha} (copiada!)")
Button(
root,
text="Mostrar",
bd=2,
bg='#107db2',
fg='white',
font=('verdana', 12, 'bold'),
command=gerar_senha
).place(relx=0.05, rely=0.55, relwidth=0.2, relheight=0.1) Button(
root,
text="Limpar",
bd=2,
bg='#107db2',
fg='white',
font=('verdana', 12, 'bold'),
command=limpar
).place(relx=0.3, rely=0.55, relwidth=0.2, relheight=0.1) Button(
root,
text="Copiar",
bd=2,
bg='#107db2',
fg='white',
font=('verdana', 12, 'bold'),
command=copiar_senha
).place(relx=0.55, rely=0.55, relwidth=0.2, relheight=0.1) Button(
root,
text="Sair",
bd=2,
bg='#107db2',
fg='white',
font=('verdana', 12, 'bold'),
command=root.destroy
).place(relx=0.8, rely=0.55, relwidth=0.15, relheight=0.1) resultado_texto = Label(
root,
text="",
font=("Arial", 12, "bold"),
bg="#cfe2f3"
)
resultado_texto.place(relx=0.05, rely=0.75, relwidth=0.9, relheight=0.2) root.mainloop()
0