1
+ from tkinter import *
2
+ import random
3
+ import string
4
+ root = Tk ()
5
+ root .title (" Password Generator" )
6
+ root .geometry ("400x350" )
7
+ root .resizable (False , False )
8
+ genpass2 = StringVar ()
9
+ def Passwordgen ():
10
+
11
+ letter = string .ascii_uppercase
12
+ letter2 = string .ascii_lowercase
13
+ digit = string .digits
14
+ punc = string .punctuation
15
+
16
+
17
+ ch = random .choice (letter )
18
+ ch4 = random .choice (letter2 )
19
+ ch2 = random .choice (digit )
20
+ ch3 = random .choice (punc )
21
+ genpass = ch + ch2 + ch3 + ch4
22
+
23
+ sample = " "
24
+ for i in range (passw .get ()):
25
+ char_type = random .choice (genpass ) # to randomize the occurance of alphabet, digit or symbol
26
+ sample = sample + random .choice (char_type )
27
+
28
+
29
+ genpass2 .set (sample )
30
+
31
+
32
+ root .config (background = "#ffffe0" )
33
+ # Declare variables
34
+ passw = IntVar ()
35
+
36
+
37
+ # Design labels
38
+ Label (root , text = "Password Generator" , bg = "#ffffe0" , fg = "#E74C3C" , font = "verdana 22 " ).place (x = 60 , y = 10 )
39
+ Label (root , text = "-------------------------------------------------" , bg = "#ffffe0" , fg = "#E74C3C"
40
+ , font = "verdana 12 " ).place (x = 15 , y = 50 )
41
+
42
+ Label (root , text = "Enter Password length " , bg = "#2C3E50" , fg = "#EAECEE" , font = "verdana 10 bold"
43
+ , padx = 2 , pady = 2 ).place (x = 7 , y = 100 )
44
+ Entry (root ,textvariable = passw ,font = "verdana 12" , width = 30 ).place (x = 7 , y = 120 )
45
+ #length = Spinbox(root, from_ = 4, to_ = 32 , textvariable = pass_len , width = 24, font='arial 16').pack()
46
+
47
+ Button (root , text = "Generate" , bg = "#fdde6c" , fg = "#000" , font = "verdana 12 "
48
+ , command = Passwordgen , relief = GROOVE ).place (x = 7 , y = 180 )
49
+
50
+ Label (root , text = "Generated Password" , bg = "#2C3E50" , fg = "#EAECEE"
51
+ , font = "verdana 10 bold" , padx = 2 , pady = 2 ).place (x = 7 , y = 250 )
52
+ Entry (root , textvariable = genpass2 , width = 35 , font = "verdana 12" ).place (x = 7 , y = 270 )
53
+
54
+ statusvar = StringVar ()
55
+ statusvar .set ("By Mayuri Narute" )
56
+ Label (root , textvariable = statusvar , relief = GROOVE , bg = "#ffffe0"
57
+ , fg = "#2C3E50" , width = 60 ).place (x = - 1 , y = 328 )
58
+ root .mainloop ()
0 commit comments