here2share

# Tk_strong_password_generator.py

Dec 26th, 2021 (edited)
1,304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. # Tk_strong_password_generator.py
  2.  
  3. from tkinter import *
  4. import random
  5. import string
  6.  
  7. words = string.ascii_uppercase
  8. words2 = string.ascii_lowercase
  9. numbers = string.digits
  10. spec_char = '!@#$%'
  11.  
  12. class GenPass:
  13.  
  14.     def __init__(self, master):
  15.         frame = Frame(master) # add parent for Frame
  16.         frame.pack()
  17.  
  18.         self.printButton = Button(frame, text="Generate Password", padx=4, pady=4, command=self.generate)
  19.         self.printButton.pack(side=LEFT)
  20.  
  21.         self.quitButton = Button(frame, text="Copy to Clipboard", padx=4, pady=4, command=master.destroy) # zzz
  22.         self.quitButton.pack(side=LEFT)
  23.  
  24.         self.output = Label(master, fg="Green")
  25.         self.output.pack()
  26.  
  27.         self.generate() # genrate password at start
  28.  
  29.  
  30.     def generate(self):
  31.         password = []
  32.         for i in range(2):
  33.             password += [random.choice(words)]
  34.         for i in range(2):
  35.             password += [random.choice(words2)]
  36.         for i in range(2):
  37.             password += [random.choice(numbers)]
  38.         for i in range(2):
  39.             password += [random.choice(spec_char)]
  40.         for i in range(8):
  41.             password += [random.choice(words+words2+numbers+spec_char)]
  42.         random.shuffle(password)
  43.         password = ''.join(password)
  44.         print(password)
  45.         self.output.config(text=password)
  46.  
  47.  
  48. root = Tk()
  49. GenPass(root)
  50. root.mainloop()
Add Comment
Please, Sign In to add comment