-
Notifications
You must be signed in to change notification settings - Fork 0
/
password_generator.py
33 lines (25 loc) · 974 Bytes
/
password_generator.py
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
import random
import string
import tkinter as tk
from tkinter import messagebox
# Function to generate the password
def generate_password():
length = int(length_entry.get())
# Define the characters to use in the password
characters = string.ascii_letters + string.digits + string.punctuation
# Generate the password
password = ''.join(random.choice(characters) for _ in range(length))
# Display the password
messagebox.showinfo("Generated Password", f"Your generated password is:\n{password}")
# Create the main application window
root = tk.Tk()
root.title("Password Generator")
# Create and place the widgets
tk.Label(root, text="Password Length:").pack(pady=25)
length_entry = tk.Entry(root)
length_entry.pack(pady=5)
length_entry.insert(0, "15") # Default length
generate_button = tk.Button(root, text="Generate Password", command=generate_password)
generate_button.pack(pady=20)
# Run the main event loop
root.mainloop()