Welcome folks today in this blog post we will be building a complex password generator
in python tkinter using random and pyperclip Library. All the full source code of the application is shown below.
Get Started
In order to get started we need to install the tkinter
and random
and pyperclip
library by issuing the npm command
npm i random
npm i tkinter
npm i pyperclip
After installing all the libraries we need to make an app.py
file and copy paste the following code
app.py
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
import random import pyperclip import tkinter as tk def copyclip(): passwordcopy=result["text"] pyperclip.copy(passwordcopy) def generate1(): try: n=int(number.get()) password="" listpass=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h','i', 'j', 'k', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z','A', 'B', 'C', 'D', 'E', 'F', 'G', 'H','I', 'J', 'K', 'M', 'N', 'O', 'p', 'Q','R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y','Z'] for i in range(0,n): password+=random.choice(listpass) result["text"]=password except: result["text"]="Invalid Number" def generate2(): try: n=int(number.get()) password="" listpass=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h','i', 'j', 'k', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z','A', 'B', 'C', 'D', 'E', 'F', 'G', 'H','I', 'J', 'K', 'M', 'N', 'O', 'p', 'Q','R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y','Z','0','1','2','3','4', '5', '6', '7', '8', '9'] for i in range(0,n): password+=random.choice(listpass) result["text"]=password except: result["text"]="Invalid Number" def generate3(): try: n=int(number.get()) password="" listpass=['0','1','2','3','4', '5', '6', '7', '8', '9'] for i in range(0,n): password+=random.choice(listpass) result["text"]=password except: result["text"]="Invalid Number" def generate4(): try: n=int(number.get()) password="" listpass=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h','i', 'j', 'k', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z','A', 'B', 'C', 'D', 'E', 'F', 'G', 'H','I', 'J', 'K', 'M', 'N', 'O', 'p', 'Q','R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y','Z','0','1','2','3','4', '5', '6', '7', '8', '9','@', '#', '$', '%', '=', ':', '?', '.', '/', '|', '~', '>','*', '(', ')'] for i in range(0,n): password+=random.choice(listpass) result["text"]=password except: result["text"]="Invalid Number" window=tk.Tk() window.geometry("500x260") #width x height window.grid_columnconfigure((0,1), weight=1) window.title("Password Generator") numberlbl=tk.Label( text="Enter Number of Digits - ", width=20, font=('Helvetica', 12, 'bold') ) number=tk.Entry( width=30,) option1=tk.Button( text="1.Characters only", width=50, height=1, command=generate1, font=('Helvetica', 10, 'bold') ) option2=tk.Button( text="2.Characters and numbers only", width=50, height=1, command=generate2, font=('Helvetica', 10, 'bold') ) option3=tk.Button( text="3.Numbers only", width=50, height=1, command=generate3, font=('Helvetica', 10, 'bold') ) option4=tk.Button( text="4.Characters numbers and symbols", width=50, height=1, command=generate4, font=('Helvetica', 10, 'bold') ) texts=tk.Label( text="Generated Password is - ", height=1, width=20, font=('Helvetica', 12, 'bold') ) result=tk.Label( height=3, width=20, bg="black", fg="white", font=('Times New Roman', 12, 'italic') ) about=tk.Label( text=''' This is a password generator created by Darsh Jain. Suggestions are welcome.Contact-9867476582 ''', fg="grey", height=2,) copy=tk.Button( text="Copy To Clipboard", width=20, command=copyclip,) numberlbl.grid(row=1,column=0) number.grid(row=1,column=1) option1.grid(row=2,columnspan=2) option2.grid(row=3,columnspan=2) option3.grid(row=4,columnspan=2) option4.grid(row=5,columnspan=2) texts.grid(row=6,column=0) result.grid(row=6,column=1) copy.grid(row=7,column=1) about.grid(row=9,columnspan=2) window.mainloop() |
Now if you execute this python
script you will see the following result
Now in the above password generator you will be able to write the number of characters you want to generate the password after that you can choose what you want inside the password you can select and you can also copy to clipboard the result password.