1+ from tkinter import Tk ,Spinbox ,Label ,StringVar ,Entry ,IntVar ,Menu ,Checkbutton ,Button
2+ from tkinter .messagebox import showerror
3+ from string import ascii_lowercase ,ascii_uppercase ,digits ,punctuation
4+ from sys import exit
5+ from random import choices
6+ def About ()-> None :
7+ Root .attributes ("-disabled" ,1 )
8+ aboutwin = Tk ()
9+ aboutwin .protocol ("WM_DELETE_WINDOW" ,lambda :[Root .attributes ("-disabled" ,0 ),
10+ aboutwin .destroy ()])
11+ aboutwin .grab_set ()
12+ aboutwin .title ("About" )
13+ aboutwin .geometry ("234x85" )
14+ aboutwin .resizable (False ,False )
15+ Label (aboutwin ,font = ("Tahoma" ,10 ),text = "A Simple Python Password Generator" ).place (x = 5 ,y = 0 )
16+ a = StringVar (aboutwin )
17+ a .set ("Github: Github.com/Vahab-Programmer" )
18+ b = StringVar (aboutwin )
19+ b .set ("Email: Vahab.Goudarzi.1390@Gmail.com" )
20+ Entry (aboutwin ,width = 31 ,textvariable = a ,font = ("Tahoma" ,9 ),state = "readonly" ).place (x = 5 ,y = 28 )
21+ Entry (aboutwin ,width = 31 ,textvariable = b ,font = ("Tahoma" ,9 ),state = "readonly" ).place (x = 5 ,y = 56 )
22+ aboutwin .mainloop ()
23+ def PasswdGen (chars :str )-> None :output .set ("" .join (choices (chars ,k = length .get ())))
24+ def Generate ()-> None :
25+ output .set ("" )
26+ up = upp .get ()
27+ lo = low .get ()
28+ sm = smy .get ()
29+ nu = num .get ()
30+ if length .get () >= 8 and length .get () <= 128 :
31+ if custom .get ():
32+ if custom_char .get () != "" :PasswdGen (custom_char .get ());return None
33+ else :showerror ("Error" ,"You Need To Write You'r Characters in custom char field" )
34+ if not up and not lo and not sm and not nu :showerror ("Error" ,"You Need to Select A Option!" );return None
35+ char = ""
36+ if up :char += ascii_uppercase
37+ if lo :char += ascii_lowercase
38+ if sm :char += punctuation
39+ if nu :char += digits
40+ PasswdGen (char )
41+ elif length .get () >= 129 :showerror ("Error" ,"Lenght Cannot Be Upper Than 128" );length .set (128 )
42+ else :showerror ("Error" ,"Lenght Cannot Be Lower Than 8" );length .set (8 )
43+ def custom_config ()-> None :
44+ d = {"state" :"disable" }
45+ e = {"state" :"normal" }
46+ if custom .get ():
47+ custom_e .config (e )
48+ up_c .config (d )
49+ low_c .config (d )
50+ sym_c .config (d )
51+ num_c .config (d )
52+ else :
53+ custom_e .config (d )
54+ up_c .config (e )
55+ low_c .config (e )
56+ sym_c .config (e )
57+ num_c .config (e )
58+ Root = Tk ()
59+ Root .title ("PasswdGen V3" )
60+ Root .geometry ("250x300+500+150" )
61+ Root .resizable (False ,False )
62+ menubar = Menu (Root )
63+ menubar .add_command (label = "About" ,command = About )
64+ menubar .add_command (label = "Exit" ,command = exit )
65+ Root .config (menu = menubar )
66+ output = StringVar ()
67+ custom_char = StringVar ()
68+ upp = IntVar ()
69+ low = IntVar ()
70+ smy = IntVar ()
71+ num = IntVar ()
72+ custom = IntVar ()
73+ length = IntVar ()
74+ Entry (Root ,textvariable = output ,width = 25 ,bd = 10 ,background = "blue" ,foreground = "white" ).place (x = 40 ,y = 25 )
75+ custom_e = Entry (Root ,textvariable = custom_char ,width = 30 ,bd = 3 ,state = "disabled" )
76+ custom_e .place (x = 32 ,y = 185 )
77+ Label (Root ,text = "Options" ,font = ("Tahoma" ,11 )).place (x = 100 ,y = 75 )
78+ Label (Root ,text = "Lenght" ,font = ("Tahoma" ,12 )).place (x = 55 ,y = 215 )
79+ up_c = Checkbutton (Root ,text = "Upper Case" ,font = ("Tahoma" ,10 ),variable = upp ,onvalue = 1 ,offvalue = 0 )
80+ up_c .place (x = 35 ,y = 100 )
81+ low_c = Checkbutton (Root ,text = "Lower Case" ,font = ("Tahoma" ,10 ),variable = low ,onvalue = 1 ,offvalue = 0 )
82+ low_c .place (x = 135 ,y = 100 )
83+ sym_c = Checkbutton (Root ,text = "Symbols" ,font = ("Tahoma" ,10 ),variable = smy ,onvalue = 1 ,offvalue = 0 )
84+ sym_c .place (x = 35 ,y = 125 )
85+ num_c = Checkbutton (Root ,text = "Numbers" ,font = ("Tahoma" ,10 ),variable = num ,onvalue = 1 ,offvalue = 0 )
86+ num_c .place (x = 135 ,y = 125 )
87+ Checkbutton (Root ,text = "Custom Char" ,font = ("Tahoma" ,10 ),variable = custom ,onvalue = 1 ,offvalue = 0 ,command = custom_config ).place (x = 70 ,y = 150 )
88+ Spinbox (Root ,textvariable = length ,from_ = 8 ,to = 128 ,width = 12 ).place (x = 130 ,y = 220 )
89+ Button (Root ,text = "Generate" ,width = 18 ,font = ("Tahoma" ,13 ),command = Generate ).place (x = 40 ,y = 250 )
90+ Root .mainloop ()
0 commit comments