-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator.py
More file actions
66 lines (54 loc) · 2.18 KB
/
generator.py
File metadata and controls
66 lines (54 loc) · 2.18 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
54
55
56
57
58
59
60
61
62
63
64
65
66
import tkinter as tk
from tkinter import messagebox
import random
import string
def generate_password():
length = length_var.get()
include_digits = digits_var.get()
include_symbols = symbols_var.get()
# Base characters: always include letters
characters = string.ascii_letters
if include_digits:
characters += string.digits
if include_symbols:
characters += string.punctuation
# Generate the random string
try:
password = "".join(random.choice(characters) for _ in range(length))
result_entry.delete(0, tk.END) # Clear previous result
result_entry.insert(0, password) # Insert new password
except IndexError:
messagebox.showerror("Error", "Something went wrong generating the password.")
def copy_to_clipboard():
password = result_entry.get()
if password:
root.clipboard_clear()
root.clipboard_append(password)
messagebox.showinfo("Success", "Password copied to clipboard!")
else:
messagebox.showwarning("Warning", "Generate a password first!")
# --- GUI Setup ---
root = tk.Tk()
root.title("Python Password Generator")
root.geometry("400x300")
# Title Label
tk.Label(root, text="Secure Password Generator", font=("Arial", 16, "bold")).pack(pady=10)
# Options
frame = tk.Frame(root)
frame.pack(pady=10)
# Length Selector
tk.Label(frame, text="Length:").grid(row=0, column=0, padx=5)
length_var = tk.IntVar(value=12)
tk.Spinbox(frame, from_=4, to=32, textvariable=length_var, width=5).grid(row=0, column=1, padx=5)
# Checkboxes
digits_var = tk.BooleanVar(value=True)
symbols_var = tk.BooleanVar(value=True)
tk.Checkbutton(frame, text="Include Numbers", variable=digits_var).grid(row=1, column=0, columnspan=2, sticky="w")
tk.Checkbutton(frame, text="Include Symbols", variable=symbols_var).grid(row=2, column=0, columnspan=2, sticky="w")
# Buttons
tk.Button(root, text="Generate Password", command=generate_password, bg="#4CAF50", fg="white").pack(pady=10)
result_entry = tk.Entry(root, font=("Arial", 12), justify="center", width=25)
result_entry.pack(pady=5)
tk.Button(root, text="Copy to Clipboard", command=copy_to_clipboard).pack(pady=5)
# Start the Loop
root.mainloop()