Password Generator in Python (With GUI)
In this tutorial, we will build a password generator using Python with a graphical user interface.
This application allows users to generate strong and random passwords based on selected criteria.
1. Requirements
Make sure Python is installed on your system.
Download Python: https://www.python.org/downloads/
2. Steps to Run the Project
Step 1: Install Python IDE.
Step 2: Copy and paste the code into your IDE.
Step 3: Run the program.
Step 4: Select password length and options.
Step 5: Click generate to create password.
3. Python Code
Python
Password Generator using Tkinter
import tkinter as tk
import random
import string
def generate_password():
length = int(length_entry.get())
chars = ""
if var_upper.get():
chars += string.ascii_uppercase
if var_lower.get():
chars += string.ascii_lowercase
if var_digits.get():
chars += string.digits
if var_symbols.get():
chars += string.punctuation
if chars == "":
result_label.config(text="Select at least one option")
return
password = "".join(random.choice(chars) for _ in range(length))
result_label.config(text=password)
root = tk.Tk()
root.title("Password Generator")
# Length
length_label = tk.Label(root, text="Password Length:")
length_label.pack()
length_entry = tk.Entry(root)
length_entry.pack()
# Options
var_upper = tk.IntVar()
var_lower = tk.IntVar()
var_digits = tk.IntVar()
var_symbols = tk.IntVar()
tk.Checkbutton(root, text="Uppercase", variable=var_upper).pack()
tk.Checkbutton(root, text="Lowercase", variable=var_lower).pack()
tk.Checkbutton(root, text="Digits", variable=var_digits).pack()
tk.Checkbutton(root, text="Symbols", variable=var_symbols).pack()
# Button
generate_btn = tk.Button(root, text="Generate Password", command=generate_password)
generate_btn.pack()
# Result
result_label = tk.Label(root, text="Your password will appear here")
result_label.pack()
root.mainloop()
4. Output
A GUI window appears where users can select password criteria and generate a secure password.
The generated password is displayed instantly on the screen.
Conclusion
This project helps in understanding random generation and GUI design in Python.
It is useful for creating secure passwords for real-world applications.
Codecrown