-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
32 lines (26 loc) · 964 Bytes
/
Copy pathmain.py
File metadata and controls
32 lines (26 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import secrets
import string
import PySimpleGUI as sg
def generate_password(length):
caracteres = string.ascii_letters + string.punctuation + string.digits
senha = ''.join(secrets.choice(caracteres) for i in range(length))
return senha
layout = [
[sg.Text('Digite o tamanho da senha que você deseja:')],
[sg.Input(key='-LENGTH-', size=(20, 1))],
[sg.Button('Gerar Senha'), sg.Button('Sair')],
[sg.Text(size=(40, 1), key='-OUTPUT-')]
]
window = sg.Window('Gerador de Senha', layout, icon='key.icon')
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED or event == 'Sair':
break
elif event == 'Gerar Senha':
try:
length = int(values['-LENGTH-'])
password = generate_password(length)
window['-OUTPUT-'].update(password)
except ValueError:
window['-OUTPUT-'].update('Por favor, insira um número inteiro válido.')
window.close()