How To Create Password Generator With GUI Using Python

Posted by Suraj Singh on February 25, 2017 · 19 mins read
hii readers,



                                   Today's Tutorial is about how to create random Password Generator using python and tkinter or you can say how to create password generator using python.


so, let's start but first if you are new visitor then don't forget to check our index page because there you will find really very interesting stuff.

Here, For Today's Topic, Follow Below Steps.

1. Create A Folder Called "Password_Gen"

2. Inside That Folder, Create New Python Script Called "Generate_Password.py"

3. And Also create another new folder called "toolkit"

4. Inside toolkit folder, create three new python script called 

               "__init__.py",

               "notification.py",

               "numbergenerator.py".

Now, Folder Directory looks like:

    Password_Gen
        |
        | --->   Generate_Password.py
        |
        | --->   toolkit
                     |
                     | --->  __init__.py
                     | --->  notification.py
                     | --->  numbergenerator.py


              Here, I am Sharing My Demo Codes But If You Want More Better Example Then, You Can Modify these codes yourself or Download This Script From My GitHub repository (link given at the end of these codes ).

1.  Generate_Password.py


#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# ---------------- READ ME ---------------------------------------------
# This Script is Created Only For Practise And Educational Purpose Only
# This Script Is Created For http://www.bitforestinfo.com
# This Script is Written By
__author__='''

######################################################
By
######################################################

Suraj Singh


surajsinghbisht054@gmail.com
http://www.bitforestinfo.com/


######################################################
'''
print (__author__)
# Importing Module
try:
import Tkinter,ttk
except Exception as e:
print e
import tkinter as Tkinter
import tkinter.ttk as ttk

from toolkit import numbergenerator as ng
from toolkit import notification as nt

# Creating Main Class
class Window(Tkinter.Tk):
def __init__(self, *args, **kwargs):
Tkinter.Tk.__init__(self, *args, **kwargs)
self['padx']=10
self['pady']=10
self.creating_password_panel()
self.creating_input_panels()

def creating_password_panel(self):
self.Password=Tkinter.StringVar()
self.PasswordLength=Tkinter.IntVar()
self.PasswordLength.set(12)
frame=Tkinter.LabelFrame(self,text='Password')
frame.pack(side='left',expand='yes',fill='both')
frame['padx']=5
frame['pady']=5
Tkinter.Entry(frame,textvariable=self.Password).pack(side='top',fill='x')
Tkinter.Button(frame,text='Generate', command=self.generate_pass).pack(side='top',fill='x')
Tkinter.Button(frame,text='Copy To Clipboard', command=self.copy_to_clipboard).pack(side='top',fill='x')
frame1=Tkinter.LabelFrame(frame,text='Password Length')
frame1.pack(side='top',expand='yes',fill='both',pady=5,padx=5,ipadx=5,ipady=5)
Tkinter.Spinbox(frame1,from_=0,to_=100,textvariable=self.PasswordLength).pack()
return

def copy_to_clipboard(self):
pas=self.Password.get()
self.clipboard_clear()
self.clipboard_append(pas)
nt.Message()
return

def generate_pass(self):
pasg=ng.number(\
length=self.PasswordLength.get(),\
digit=self.answer[0].get(),\
uppercase=self.answer[1].get(),\
lowercase=self.answer[2].get(),\
symbol=self.answer[3].get(),\
punctuation=self.answer[4].get(),\
whitespace=self.answer[5].get()\
)
self.Password.set(pasg.generate())
return

def creating_input_panels(self):
frame=Tkinter.LabelFrame(self,text='Panel')
frame.pack(side='left')
frame['padx']=10
frame['pady']=10
self.answer=[]
l=18
for i in ['Digits','Uppercase','Lowercase','Symbol','Punctuation','Whitespace']:
i=' '*(l-len(i))+i
var=Tkinter.IntVar()
var.set(1)
Tkinter.Checkbutton(frame,text=i,variable=var).pack(side='top',expand='yes',fill='both')
self.answer.append(var)
var.set(0)
return
# main trigger
#if __name__ == '__main__':
#
Window(className=" Password Generator").mainloop()

2.  __init__.py


#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# ---------------- READ ME ---------------------------------------------
# This Script is Created Only For Practise And Educational Purpose Only
# This Script Is Created For http://www.bitforestinfo.com
# This Script is Written By
__author__='''

######################################################
By
######################################################

Suraj Singh


surajsinghbisht054@gmail.com
http://www.bitforestinfo.com/


######################################################
'''
pass

3. notification.py


#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# ---------------- READ ME ---------------------------------------------
# This Script is Created Only For Practise And Educational Purpose Only
# This Script Is Created For http://www.bitforestinfo.com
# This Script is Written By
__author__='''

######################################################
By
######################################################

Suraj Singh


surajsinghbisht054@gmail.com
http://www.bitforestinfo.com/


######################################################
'''
try:
import Tkinter
except:
import tkinter as Tkinter

import time

class Message(Tkinter.Toplevel):
def __init__(self,width=700,height=200,text="Copy To Clipboard",bg="white",font=('arial 20 bold italic')):
Tkinter.Toplevel.__init__(self)
self.font=font
self.text=text
self.bg=bg
self.width=width
self.height=height
self.focus_force()
self.overrideredirect(True)
self.coordinate_position()
self.creating_label()
self.timer_is_starting()

def creating_label(self):
Tkinter.Label(self,text=self.text,bg=self.bg,font=self.font).pack(expand='yes',fill='both')
return

def coordinate_position(self):
self.geometry("%dx%d+%d+%d" % (self.width,self.height,\
self.winfo_screenwidth()/2-(self.width/2),\
self.winfo_screenheight()/2-(self.height/2),\
))
return

def timer_is_starting(self):
x=1.0
for i in range(110):
time.sleep(0.02)
self.update_idletasks()
self.update()
self.attributes('-alpha',x)
x=x-0.01
return

def main():
#root=Tkinter.Tk()
Message()
#Tkinter.Button(root,text="Test",command=Message).pack()

return

# Main Trigger
if __name__ == '__main__':
main()

4. numbergenerator.py


#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# ---------------- READ ME ---------------------------------------------
# This Script is Created Only For Practise And Educational Purpose Only
# This is an Example Of Tkinter Canvas Graphics
# This Script Is Created For http://www.bitforestinfo.com
# This Script is Written By
__author__='''

######################################################
By
######################################################

Suraj Singh


surajsinghbisht054@gmail.com
http://www.bitforestinfo.com/


######################################################
'''
# ----------- Importing Module --------------------------
import random,string

class number:
def __init__(self, length=12,digit=True,uppercase=True,lowercase=True,symbol=True,punctuation=True,whitespace=0):
self.length=length
self.digit=digit
self.uppercase=uppercase
self.lowercase=lowercase
self.symbol=symbol
self.punctuation=punctuation
self.whitespace=whitespace

def generate(self):
data=[]
storeobj=[]
if self.digit:
storeobj.append(string.digits)
if self.symbol:
storeobj.append("#@&-_")
if self.uppercase:
storeobj.append(string.ascii_uppercase)
if self.lowercase:
storeobj.append(string.ascii_lowercase)
if self.punctuation:
storeobj.append(string.punctuation)
if self.whitespace:
storeobj.append(string.whitespace)
for i in range(12):
ch=random.choice(storeobj)
data.append(str(random.choice(ch)))
random.shuffle(data)
password=''
for i in data:
password=password+i
return password


if __name__ == '__main__':
k=number()
print (k.generate())

Copy, These Code on scripts (script name at the top of codes).

Here, Below is my screenshots.



For Downloading Raw Scripts Click Here.

For More Update, Visit Our Regularly. 
And Subscribe Our Blog, 

Follow Us and share it.
For Any Type of Suggestion Or Help
Contact me:
Suraj
surajsinghbisht054@gmail.com