Password Generator with Python

In this article, you will learn how to create a unique password generator app using python in a few simple steps. I will first create a program to generate unique passwords. Next, I will show you how we can turn this simple program into a GUI for Unique Password Generator with Python and Tkinter.

Password Generator with Python

I will use the random module which will allow you to take variables from the characters variable. If you want the resulting password to be more difficult to crack, I strongly suggest that you add more than just numbers and letters. I added numbers, capitals and a few other signs. Another good idea is to lengthen them:

import random
characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%&*1234567890"Code language: JavaScript (javascript)

I will use the length variable to get the length of the resulting password:

length = int(input("Enter Password length"))
password = ""Code language: JavaScript (javascript)

Now, let’s run a loop to execute the code:

for i in range(length+1):
    password += random.choice(characters)
print(password)Code language: PHP (php)


The result looks good. I will not stop here. Let’s create a GUI for creating a password generator application. I will use the Tkinter module in python for this task. 

Password Generator with Python and Tkinter

Tkinter is the standard GUI library for Python. Python, when combined with Tkinter, provides a quick and easy way to build GUI applications. Now, in this section, I will proceed to build the password generator using Python which will be a GUI output. To get the unique password you have to press the button to generate a password.

Also, Read – Text to Speech with Python.

I will use the same procedure as used above. The difference will be in strings. I have written all letters, symbols and numbers in the above program, here I will not do that, as I will be using the String module for this task to short our code, which provides all necessary methods for the same. Now, let’s build our GUI application for Password Generator with python:

import tkinter as tk
import string
import random
def generate_password():
    password = []
    for i in range(5):
        alpha = random.choice(string.ascii_letters)
        symbol = random.choice(string.punctuation)
        numbers = random.choice(string.digits)
        passwords = " ".join(str(x)for x in password)
root = tk.Tk()
button = tk.Button(root, text="Generate Password", command=generate_password)
button.grid(row=1, column=1)
label = tk.Label(root, font=("times", 15, "bold"))
label.grid(row=4, column=2)
root.mainloop()Code language: JavaScript (javascript)
Password Generator with python and tkinter

Also, Read – What is Deep Learning?

Now, after running the code, you will see the output something like the image above. You have to click on the button to generate a password. I hope you liked this article. Feel free to ask your valuable questions in the comments section below. You can also follow me on Medium to learn every topic of Machine Learning.

Also, Read – Emotion Detection Model with Machine Learning.

Follow Us:

Aman Kharwal
Aman Kharwal

I'm a writer and data scientist on a mission to educate others about the incredible power of data📈.

Articles: 1501

Leave a Reply