用python写一个带有gui界面的密码生成器
程序员文章站
2022-03-27 20:44:47
需要用到的库:tkinter:构建gui界面pyperclip:复制功能random:生成随机数string:处理字符串代码:from tkinter import *import random, s...
需要用到的库:
tkinter:构建gui界面
pyperclip:复制功能
random:生成随机数
string:处理字符串
代码:
from tkinter import * import random, string import 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的知识,资讯,实用工具欢迎关注python客栈
以上就是用python写一个带有gui界面的密码生成器的详细内容,更多关于python gui密码生成器的资料请关注其它相关文章!