用户:L0_0查看:0 回复:0 评论:0 创建时间:2021-03-29T21:38:49
【作品展示】

【作品介绍】
密码生成,就不用担心进入系统了
【作品源代码】
import random
import string
from tkinter import Tk, Menu, Entry, Label, Button, messagebox
root = Tk()
root.title('密码生成与输入')
root.resizable(width=False, height=False)
over = True
password_list = []
Label(root, width=12, height=3, text='输入密码').grid(column=0, row=0)
Label(root, width=12, height=3, text='确认密码').grid(column=0, row=1)
password_1 = Entry(root, width=90, show='*')
password_1.grid(column=1, row=0)
password_2 = Entry(root, width=90, show='*')
password_2.grid(column=1, row=1)
def show():
if password_1['show'] == '*':
password_1['show'] = ''
password_2['show'] = ''
else:
password_1['show'] = '*'
password_2['show'] = '*'
def judge():
global over
if over:
messagebox.showerror('密码生成与输入', '未生成密码,不可提交。')
return
if password_1.get() != password_2.get():
messagebox.showerror('密码生成与输入', '两个密码框输入不同,无法判断。')
return
else:
if password_1.get() == password_list[-1]:
messagebox.showinfo('密码生成与输入', '密码正确。')
over = True
return
else:
messagebox.showerror('密码生成与输入', '密码错误。')
Button(root, width=9, height=3, command=show, text='显示').grid(column=2, row=0)
Button(root, width=9, height=3, command=judge, text='提交').grid(column=2, row=1)
def show_password():
global over, the_right_password
password = make_password()
if messagebox.askokcancel('生成密码', '你的密码是' + password + ',还需要另一个密码吗?'):
show_password()
else:
the_right_password = password
password_list.append(the_right_password)
over = False
def make_password():
password = ''
for i in range(random.randint(1, 10)):
password += random.choice(string.printable)
return password
menubar = Menu(root)
menubar.add_command(label='生成密码', command=show_password)
menubar.add_command(label='已生成的密码', command=lambda title='已生成的密码', msg=password_list:messagebox.showinfo(title, msg))
menubar.add_separator()
menubar.add_command(label='退出程序', command=root.quit)
root.config(menu=menubar)
root.mainloop()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn