In this video I’ll show you how to build a Strong Password Generator App With Tkinter and Python.

In this app we’ll generate a strong password using Python’s built in ability to convert numbers to ASCII characters using the chr() function. We’ll generate a random number between 33 and 126 and then convert that to ANSCII to create a strong password.

Python Code: password.py
(Github Code)

from tkinter import *
from random import randint

root = Tk()
root.title('Codemy.com - Strong Password Generator')
root.iconbitmap('c:/gui/codemy.ico')
root.geometry("500x300")


# Generate Random Strong Password
def new_rand():
	# Clear Our Entry Box
	pw_entry.delete(0, END)

	# Get PW Length and convert to integer
	pw_length = int(my_entry.get())

	# create a variable to hold our password
	my_password = ''

	# Loop through password length
	for x in range(pw_length):
		my_password += chr(randint(33,126))

	# Output password to the screen
	pw_entry.insert(0, my_password)


# Copy to clipboard
def clipper():
	# Clear the clipboard
	root.clipboard_clear()
	# Copy to clipboard
	root.clipboard_append(pw_entry.get())

# Label Frame
lf = LabelFrame(root, text="How Many Characters?")
lf.pack(pady=20)

# Create Entry Box To Designate Number of Characters
my_entry = Entry(lf, font=("Helvetica", 24))
my_entry.pack(pady=20, padx=20)

# Create Entry Box For Our Returned Password
pw_entry = Entry(root, text='', font=("Helvetica", 24), bd=0, bg="systembuttonface")
pw_entry.pack(pady=20)

# Create a frame for our Buttons
my_frame = Frame(root)
my_frame.pack(pady=20)

# Create our Buttons
my_button = Button(my_frame, text="Generate Strong Password", command=new_rand)
my_button.grid(row=0, column=0, padx=10)

clip_button = Button(my_frame, text="Copy To Clipboad", command=clipper)
clip_button.grid(row=0, column=1, padx=10)

root.mainloop()

John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of the first dot com boom. After that he developed the award-winning Submission-Spider search engine submission software that's been used by over 3 million individuals, businesses, and governments in over 42 countries. He's written several Amazon #1 best selling books on coding, and runs a popular Youtube coding channel.

View all posts

Add comment

Your email address will not be published. Required fields are marked *

John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of...