代码
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2024/3/26 15:22
# @Author : wyq
# @File : 部署测试.py
import random
import string
from tkinter import *def generate_password(length):characters = string.ascii_letters + string.digits + string.punctuationpassword = ''.join(random.choice(characters) for _ in range(length))return passworddef generate_selected_password():length = var.get()password = generate_password(length)password_text.insert(END, password + '\n') # 插入密码到文本框末尾,并换行def default_password():return "1qaz@WSX1234"def display_default_password():password = default_password()password_text.insert(END, password + '\n') # 插入默认密码到文本框末尾,并换行window = Tk()
window.title("复杂密码度生成器")
window.geometry('500x300')
bold_font = ('Arial', 12, 'bold')
glob_label = Label(window, text='Password Length:', width=15, height=2, font=bold_font, fg='red')
glob_label.grid(row=0, column=0, pady=10)
window.grid_columnconfigure(0, weight=1) # 增加列权重var = IntVar()length1 = Radiobutton(window, text='10', variable=var, value=10)
length1.grid(row=1, column=0, pady=5)
length2 = Radiobutton(window, text='12', variable=var, value=12)
length2.grid(row=2, column=0, pady=5)generate_button1 = Button(window, text="生成密码", command=generate_selected_password)
generate_button1.grid(row=4, column=0, pady=10)generate_button2 = Button(window, text="默认密码", command=display_default_password)
generate_button2.grid(row=5, column=0, pady=10)password_text = Text(window, height=10, width=30, wrap=WORD)
password_text.grid(row=6, column=0, pady=10, padx=20)window.mainloop()
效果