Python Tkinter GUI Script to Built a Secure Random Password Generator Desktop App Using Random Library Full Project For Beginners

Python Tkinter GUI Script to Built a Secure Random Password Generator Desktop App Using Random Library Full Project For Beginners

 

Welcome folks today in this post we will be building a secure random password generator desktop app in tkinter using random library. All the full source code of the application is given below.

 

 

 

Get Started

 

 

In order to get started you need to install the following libraries inside your python project using the pip command as shown below

 

pip install tkinter

 

pip install random

 

After installing these libraries make an app.py file and copy paste the following code

 

app.py

 

 

from tkinter import *
from tkinter import messagebox
import random


spc = ['@','#','$','%','&']
not_spc1 = [0,1,2,3,4,5,6,7,8,9]
not_spc2 = ['@','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
not_spc3 = ['_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']


def password_generator():
    pg = Tk()
    pg.geometry("350x150")
    pg.title("Password Generator (P-Protect)")
    pg.resizable(0,0)
    def pass_gen():
        pass_entry_text = ""
        generated = ""
        choice_lst = []
        length = random.randint(9,10)
        for i in range(length+1):
            special = random.choice(spc)
            number = random.choice(not_spc1)
            non_special = random.choice(not_spc2)
            non_special2 = random.choice(not_spc3)
            choice_lst.append(special)
            choice_lst.append(number)
            choice_lst.append(non_special)
            choice_lst.append(non_special2)
            choice = random.choice(choice_lst)
            generated += str(choice)
        pass_entry.delete(0, END)
        pass_entry_text = generated
        pass_entry.insert(END, pass_entry_text)
        # print(generated)
    empty = Label(pg, text="        ")
    empty.pack()
    pass_label = Label(pg, text="GENERATE PASSWORD", font=('bold',14), fg="red")
    pass_label.pack()
    empty = Label(pg, text="         ")
    empty.pack()
    global pass_entry_text
    pass_entry_text = StringVar()
    global pass_entry
    pass_entry = Entry(pg, textvariable=StringVar)
    pass_entry.pack()
    empty = Label(pg, text="         ")
    empty.pack()
    pass_btn = Button(pg, text="GENERATE", font=5, fg="black", bg="yellow", command=pass_gen)
    pass_btn.pack()
    pg.mainloop()

if __name__ == '__main__':
    password_generator()

 

See also  Python 3 WxPython Numeric Spinctrl or Spinner Widget Example to Select Range of Values in GUI Desktop App Full Project For Beginners

 

So now if you execute the python script app.py by typing the below command

 

python app.py

 

 

 

 

So now as you see in the above figure when you hit the generate button a new password will be generated and then you can use this password for your use

Leave a Reply