Advertisement
acclivity

tkinter-stuff

Jun 22nd, 2021
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.12 KB | None | 0 0
  1. from tkinter import *
  2. from random import randint
  3. import random
  4.  
  5. root = Tk()
  6. root.title('PinPassGen 1.0')
  7. root.geometry("500x300")
  8. root.configure(bg="lightgrey")
  9. TYPE = IntVar()
  10. result = "12345"
  11.  
  12.  
  13. # Create password
  14. def make_Password(length):
  15.     my_password = "".join([chr(randint(33, 126)) for _ in range(length)])
  16.     return my_password
  17.  
  18.  
  19. def make_Pin(length):
  20.     return "".join(random.sample(Pin, length))
  21.  
  22.  
  23. def clipper():
  24.     global result
  25.     root.withdraw()
  26.     root.clipboard_clear()
  27.     root.clipboard_append(result)
  28.     root.update()  # now it stays on the clipboard after the window is closed
  29.     # root.destroy()
  30.     # HERE THE tkinter WINDOW CLOSES - I DON'T KNOW WHY OR HOW TO PREVENT IT
  31.  
  32.  
  33. def passpin():
  34.     global result
  35.     pw_result.delete(0, END)                # Clear result field
  36.     len_str = my_entry.get()                # Get length as a string
  37.     if len_str.isdigit():                   # Check for numeric length
  38.         res_length = int(len_str)           # get required length of Pin or Password
  39.         if TYPE.get() == 1:                 # Compute a PIN
  40.             if res_length > 10:
  41.                 result = "Max Pin length is 10"
  42.             else:
  43.                 result = make_Pin(res_length)       # Call make_Pin(), telling it the length required
  44.         else:                                   # Generate a Password
  45.             result = make_Password(res_length)  # Call make_Password(), telling it the length required
  46.     else:
  47.         result = "Invalid length"
  48.     pw_result.insert(0, result)             # Display PIN or Password in output field
  49.  
  50.  
  51. # Create a frame for our input box
  52. lf = LabelFrame(root, text="How Many Characters?", bg="lightgrey")
  53. lf.grid(row=0, column=0, padx=50)
  54.  
  55. # Create a frame for our Radio Buttons
  56. radf = LabelFrame(root, text="Choose Security Type", bg="lightgrey")
  57. radf.grid(row=1, column=0, padx=50)
  58.  
  59. # create a frame for our buttons
  60. my_frame = LabelFrame(root, text="Generate/Copy", bg="lightgrey")
  61. my_frame.grid(row=2, column=0, padx=50)
  62.  
  63. # create a frame for our output box
  64. my_output = LabelFrame(root, text="Your New Pin/Password", bg="lightgrey")
  65. my_output.grid(row=3, column=0, padx=50)
  66.  
  67. # Create entry box to designate number of characters
  68. my_entry = Entry(lf, font=("helvetica", 24))
  69. my_entry.grid(row=0, column=0)
  70.  
  71. # create result box for our returned password
  72. pw_result = Entry(my_output, text='', font=("helvetica", 24), bd=0, bg="lightgrey")
  73. pw_result.grid(row=0, column=0)
  74.  
  75. # create our buttons
  76. # my_button = Button(my_frame, text="Generate Pin/Pass", command=Password, bg="lightgrey")
  77. my_button = Button(my_frame, text="Generate Pin/Pass", command=passpin, bg="lightgrey")
  78. my_button.grid(row=1, column=0, padx=10)
  79.  
  80. clip_button = Button(my_frame, text="Copy To Clipboard", command=clipper, bg="lightgrey")
  81. clip_button.grid(row=1, column=1)
  82.  
  83. # create radio buttons
  84. Radiobutton(radf, text="Pin", bg="lightgrey", padx=20, variable=TYPE, value=1).pack(anchor=W)
  85. Radiobutton(radf, text="Password", bg="lightgrey", padx=20, variable=TYPE, value=2).pack(anchor=W)
  86.  
  87. # function
  88. Pin = "1234567890"              # MJK
  89.  
  90. root.mainloop()
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement