python2.7写的图形密码生成器

Posted liumt-blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python2.7写的图形密码生成器相关的知识,希望对你有一定的参考价值。

#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()




以上是关于python2.7写的图形密码生成器的主要内容,如果未能解决你的问题,请参考以下文章

Python2.7的安装并与Python3.8共存

Python2.7-内置类型

Python2.7字符编码详解

基于python2.7+HTMLTestrunner生成报告后样式美化图版以及源码获取

python2.7导入mysqldb

python2.7 使用生成器方式实现斐波那契数列