-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI_password_generator.py
More file actions
50 lines (39 loc) · 2.04 KB
/
GUI_password_generator.py
File metadata and controls
50 lines (39 loc) · 2.04 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from tkinter import *
import string
import random
import pyperclip
########## Password Generator ##########
password_chars = string.ascii_letters + string.digits + string.punctuation
def password_generator(event):
password_field.delete(0, END)
length = int(char_input.get())
password = "".join([random.choice(password_chars) for _ in range(length)])
password_field.insert(0, password)
pyperclip.copy(password)
########## User Interface ##########
window = Tk()
window.title("Password Generator")
window.config(padx=50, pady=50, bg="#383e56")
label_title = Label(text="Password Generator",
bg="#383e56",
fg="#c5d7bd",
font=("Arial", 35, "bold"))
label_title.grid(row=0, column=0, columnspan=3, pady=30)
label_before_input = Label(text="I want a password with",bg="#383e56",fg="#c5d7bd",font=("Arial", 20, "bold"))
label_before_input.grid(row=1, column=0)
char_input = Entry(bg="#FFFFFF")
char_input.grid(row=1, column=1)
char_input.insert(0, "6") ## By default we are taking length of password as 6 but user can change it while using it.
char_input.focus()
label_after_input = Label(text="characters.",bg="#383e56",fg="#c5d7bd",font=("Arial", 20, "bold"))
label_after_input.grid(row=1, column=2)
generate_password_button = Button(text="Generate Password & Copy to Clipboard",bg="#ffffff",height=4,width=55,command=password_generator)
#### For saving some time here Enter key event is used which when the user enter the password length
#### then he just need to press Enter and don't need to press the mouse cursor on the Generate Password
window.bind("<Return>",password_generator)
generate_password_button.grid(row=2, column=0, columnspan=3, padx=50, pady=50)
#### Whenever the Escape key is pressed the Window screen of Password Generator will get exit/destroy
window.bind("<Escape>",exit)
password_field = Entry(bg="white",font=("Arial", 15, "bold"), width=40)
password_field.grid(row=3, column=0, columnspan=3)
window.mainloop()