欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

用python写一个带有gui界面的密码生成器

程序员文章站 2022-08-07 18:01:29
需要用到的库: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写一个带有gui界面的密码生成器

想要了解更多关于python的知识,资讯,实用工具欢迎关注python客栈

用python写一个带有gui界面的密码生成器

以上就是用python写一个带有gui界面的密码生成器的详细内容,更多关于python gui密码生成器的资料请关注其它相关文章!