-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestpass.py
More file actions
53 lines (39 loc) · 1.68 KB
/
testpass.py
File metadata and controls
53 lines (39 loc) · 1.68 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
51
52
53
import string
import random
import tkinter as tk
# function to generate a random password
def generate_password():
# define the possible characters for the password
characters = string.ascii_letters + string.digits + string.punctuation
# generate a random password of length 12
password = ''.join(random.choice(characters) for i in range(12))
# update the password label with the new password
password_label.config(text=password)
# function to generate a random username
def generate_username():
# define the possible characters for the username
characters = string.ascii_lowercase + string.digits
# generate a random username of length 8
username = ''.join(random.choice(characters) for i in range(8))
# update the username label with the new username
username_label.config(text=username)
# create the tkinter window
window = tk.Tk()
window.title("Password and Username Generator")
# create the username label
username_title = tk.Label(window, text="Username:")
username_title.grid(row=0, column=0)
username_label = tk.Label(window, text="")
username_label.grid(row=0, column=1)
# create the password label
password_title = tk.Label(window, text="Password:")
password_title.grid(row=1, column=0)
password_label = tk.Label(window, text="")
password_label.grid(row=1, column=1)
# create the generate username and password buttons
generate_username_button = tk.Button(window, text="Generate Username", command=generate_username)
generate_username_button.grid(row=2, column=0)
generate_password_button = tk.Button(window, text="Generate Password", command=generate_password)
generate_password_button.grid(row=2, column=1)
# run the window
window.mainloop()