需要用到的库:
代码: 12345678910111213141516171819202122232425262728293031323334353637383940414243from tkinter import *import random, stringimport pyperclip root =Tk()root.geometry("400x400")root.resizable(0,0)root.title("密码生成器") heading = Label(root, text = '密码' , font ='arial 15 bold').pack() pass_label = Label(root, text = '密码长度', font = 'arial 10 bold').pack()pass_len = IntVar()length = Spinbox(root, from_ = 8, to_ = 32 , textvariable = pass_len , width = 15).pack() pass_str = StringVar() def Generator(): password = '' for x in range (0,4): password = random.choice(string.ascii_uppercase)+random.choice(string.ascii_lowercase)+random.choice(string.digits)+random.choice(string.punctuation) for y in range(pass_len.get()- 4): password = password+random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits + string.punctuation) pass_str.set(password) Button(root, text = "获取密码" , command = Generator ).pack(pady= 5) Entry(root , textvariable = pass_str).pack() def Copy_password(): pyperclip.copy(pass_str.get()) Button(root, text = '复制密码', command = Copy_password).pack(pady=5) root.mainloop() 运行效果: |
|
用python写一个带有gui界面的密码生成器
【摘要】 需要用到的库:tkinter:构建gui界面pyperclip:复制功能random:生成随机数string:处理字符串代码:12345678910111213141516171819202122232425262728293031323334353637383940414243from tkinter import *import random, stringimport pypercli...
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区),文章链接,文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件至:huaweicloud.bbs@huawei.com进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容。
评论 (0)
登录后可评论,请 登录 或 注册
评论您没有权限执行当前操作