python2.7写的图形密码生成器
程序员文章站
2023-02-03 17:49:09
#coding:utf8import random,wxdef password(event): a = [chr(i) for i in range(97,123)] b = [chr(i) for i in range(65,91)] c = ['0','1','2','3','4','5',' ......
#coding:utf8
import random,wx
def password(event):
a = [chr(i) for i in range(97,123)]
b = [chr(i) for i in range(65,91)]
c = ['0','1','2','3','4','5','6','7','8','9']
d = ['!','@','#','$','%','^','&','*','(',')','=','_','+','/','?']
set1 = a + b + c + d
set2 = a + b + c
num = int(length.getvalue())
if switch.getvalue() == 0:
passwd = ''.join(random.sample(set1,num))
contents.setvalue(passwd)
else:
passwd = ''.join(random.sample(set2,num))
contents.setvalue(passwd)
app = wx.app()
win = wx.frame(none,-1,title=u'密码生成器',size=(480,200))
bkg = wx.panel(win,-1)
# tt = wx.statictext(bkg,-1,u'屏蔽输入字符')
# delete = wx.textctrl(bkg,-1)
right = wx.button(bkg,-1,label=u'确定生成')
right.bind(wx.evt_button,password)
stxt = wx.statictext(bkg,-1,u'请输入你的密码长度位数!' )
length = wx.textctrl(bkg,-1,size=(50,27))
switch = wx.checkbox(bkg, -1,u'关闭特殊字符',(150, 20))
sobx = wx.boxsizer()
sobx.add(stxt,proportion=0,flag=wx.all,border=5)
sobx.add(length,proportion=1,border=5)
sobx.add(switch,proportion=0,flag=wx.all | wx.align_right,border=5)
sobx.add(right,proportion=0,flag=wx.expand,border=5)
contents = wx.textctrl(bkg,-1)
cobx = wx.boxsizer()
cobx.add(contents,proportion=1,flag=wx.expand,border=5)
dobx = wx.boxsizer()
# dobx.add(delete,proportion=1,flag=wx.all,border=5)
robx = wx.boxsizer(wx.vertical)
robx.add(cobx,proportion=1,flag=wx.expand | wx.all,border=5)
robx.add(sobx,proportion=0,flag=wx.all,border=5)
# robx.add(dobx,proportion=0,flag=wx.expand,border=5)
bkg.setsizer(robx)
win.show()
app.mainloop()
上一篇: 您要批评我就直说