from random import *
from tkinter import *
num="0123456789"
alphanum="abcdefghijklmnopqrstuvwsyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
spalphanum="abcdefghijklmnopqrstuvwsyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'#@+(){}"
# passlen = int (input("Enter password length \n"))
# ranPass =[]
# print ("select the type of password \n1.Number\n2.Alphanum\n3.Special alphanumeric\n")
# Selecttype = int(input())
# if Selecttype == 1:
# for i in range(passlen):
# randpass.append(choice(num))
# elif if (Selecttype == 2):
# for i in range (passlen):
# randpass.append(choice(alphanum))
# else:
# for i in range (passlen):
# randpass.append(choice(spalphanum))
# result ="".join(randpass)
# print("Your random password is : "+result )
def Create_pass():
TheChoice = Tchoice.get()
if TheChoice =="":
resultBox.delete(0.0,END)
resultBox.insert(END,"\n Select the type of password you'd like")
length = int (pass_length.get())
randpass =[]
for i in range(length):
randpass.append(choice(TheChoice))
result = "".join(randpass)
TheResult = "\n *** Your Password is : "+result+" ***\n"
resultBox.delete(0.0,END)
resultBox.insert(END,TheResult)
window = Tk()
window.geometry("800*500")
window.title("Haben's Random Password Generator")
window.icobitmap(r"rand.ico")
ProgName = Lable(window,font=('Constantia',15,'bold'),text="Password Generator",fg="blue")
ProgName.grid(row=1,column=3 padx=200,pady=30)
ChooseType = Lable(window,font=('Constantia',15,'bold'),text="Choose a Type Among the 3")
ChooseType.place(relx=.03, rely=.25)
Tchoice = StringVar()
NumChoice = Radiobutton(window,font=('Times New Roman',10,'italic'),text ="Numeric", variable =Tchoice,value=num)
NumChoice.place(relx=.3 rely=.35)
AlphaNumChoice = Radiobutton(window,font=('Times New Roman',10,'italic'),text ="Alphanumeric", variable =Tchoice,value=alphanum)
AlphaNumChoice.place(relx=.3, rely =.4)
SpecialChoice = Radiobutton(window,font=('Times New Roman',10,'italic'),text ="special", variable =Tchoice,value=spalphanum)
SpecialChoice.place(relx=.3, rely =.45)
size =Lable(window,text="Size",font=('Comic Sans MS',10,'bold'))
size.place(relx=.65 , rely = .4)
pass_length = Spinbox(window,from_=8, to=100)
pass_length.place(relx=73,rely =.4)
pass_length.config(state="readonly")
GenButton = Button(window,text = "Generate",command=Create_pass)
GenButton.place(relx=.45, rely=.60)
resultBox =Text (window, height=6, width = 70)
resultBox.place(relx=.4, rely = .7)
window.mainloop()