The Password Generator project is a simple yet powerful tool that allows users to create strong, random passwords for securing their online accounts and data. This project utilizes Python’s tkinter library to create a graphical user interface (GUI) and employs the random, string, and pyperclip libraries for password generation and clipboard functionality.
By completing this project, you will learn:
To run this project on your machine, ensure you have Python installed. Follow these steps:
pip install pyperclip
#importing Libraries
from tkinter import *
import random, string
import pyperclip
### initialize window
root =Tk()
root.geometry("400x400")
root.resizable(0,0)
root.title("edSlash Coding Hub - PASSWORD GENERATOR")
# heading
heading = Label(root, text = 'PASSWORD GENERATOR' , font ='arial 15 bold').pack()
Label(root, text ='edSlash Coding Hub', font ='arial 15 bold').pack(side = BOTTOM)
### select password length
pass_label = Label(root, text = 'PASSWORD LENGTH', font = 'arial 10 bold').pack()
pass_len = IntVar()
length = Spinbox(root, from_ = 8, to_ = 32 , textvariable = pass_len , width = 15).pack()
##### define function
pass_str = StringVar()
def Generator():
password = ''
for x in range (0,4):
password = random.choice(string.ascii_uppercase)+random.choice(string.ascii_lowercase)+random.choice(string.digits)+random.choice(string.punctuation)
for y in range(pass_len.get()- 4):
password = password+random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits + string.punctuation)
pass_str.set(password)
### button
Button(root, text = "GENERATE PASSWORD" , command = Generator ).pack(pady= 5)
Entry(root , textvariable = pass_str).pack()
######## function to copy
def Copy_password():
pyperclip.copy(pass_str.get())
Button(root, text = 'COPY TO CLIPBOARD', command = Copy_password).pack(pady=5)
# loop to run program
root.mainloop()
#importing Libraries
from tkinter import *
import random, string
import pyperclip
### initialize window
root =Tk()
root.geometry("400x400")
root.resizable(0,0)
root.title("edSlash Coding Hub - PASSWORD GENERATOR")
# heading
heading = Label(root, text = 'PASSWORD GENERATOR' , font ='arial 15 bold').pack()
Label(root, text ='edSlash Coding Hub', font ='arial 15 bold').pack(side = BOTTOM)
### select password length
pass_label = Label(root, text = 'PASSWORD LENGTH', font = 'arial 10 bold').pack()
pass_len = IntVar()
length = Spinbox(root, from_ = 8, to_ = 32 , textvariable = pass_len , width = 15).pack()
##### define function
pass_str = StringVar()
def Generator():
password = ''
for x in range (0,4):
password = random.choice(string.ascii_uppercase)+random.choice(string.ascii_lowercase)+random.choice(string.digits)+random.choice(string.punctuation)
for y in range(pass_len.get()- 4):
password = password+random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits + string.punctuation)
pass_str.set(password)
### button
Button(root, text = "GENERATE PASSWORD" , command = Generator ).pack(pady= 5)
Entry(root , textvariable = pass_str).pack()
######## function to copy
def Copy_password():
pyperclip.copy(pass_str.get())
Button(root, text = 'COPY TO CLIPBOARD', command = Copy_password).pack(pady=5)
# loop to run program
root.mainloop()
1. Import Required Libraries:
o Import tkinter, random, string, and pyperclip.
2. Initialize the Application Window:
o Create a window using Tk() and set its dimensions.
3. Add GUI Elements:
o Add a label for the heading and another for the subheading.
o Create a Spinbox to select the password length.
o Create an Entry widget to display the generated password.
4. Define the Password Generator Function:
o Initialize an empty string for the password.
o Use a loop to add random characters from different categories (uppercase, lowercase, digits, punctuation) to ensure diversity.
o Fill the remaining characters with a random selection from all categories.
5. Define the Clipboard Copy Function:
o Use pyperclip to copy the generated password to the clipboard.
6. Create Buttons:
o Add a button to trigger the password generation.
o Add another button to copy the password to the clipboard.
7. Start the Main Loop:
o Use mainloop() to run the application.
1. Import Required Libraries:
o Import tkinter, random, string, and pyperclip.
2. Initialize the Application Window:
o Create a window using Tk() and set its dimensions.
3. Add GUI Elements:
o Add a label for the heading and another for the subheading.
o Create a Spinbox to select the password length.
o Create an Entry widget to display the generated password.
4. Define the Password Generator Function:
o Initialize an empty string for the password.
o Use a loop to add random characters from different categories (uppercase, lowercase, digits, punctuation) to ensure diversity.
o Fill the remaining characters with a random selection from all categories.
5. Define the Clipboard Copy Function:
o Use pyperclip to copy the generated password to the clipboard.
6. Create Buttons:
o Add a button to trigger the password generation.
o Add another button to copy the password to the clipboard.
7. Start the Main Loop:
o Use mainloop() to run the application.
Q: What is the purpose of using pyperclip?
A: pyperclip allows the program to interact with the system clipboard, making it easy to copy and paste the generated password.
Q: Can I customize the password length?
A: Yes, the Spinbox widget allows users to select a password length between 8 and 32 characters.
Q: How can I modify the character set used for password generation?
A: You can adjust the character sets by modifying the strings in the Generator function, such as string.ascii_uppercase or string.digits.
Office:- 660, Sector 14A, Vasundhara, Ghaziabad, Uttar Pradesh - 201012, India