简体   繁体   English

Python 密码生成器与 TKInter

[英]Python Password Generator with TKInter

I am coding a password generator with an interface for school and I can't seem to find out where to put the password generator piece in my program.我正在编写带有学校接口的密码生成器,但我似乎无法找到将密码生成器放在我的程序中的位置。

import random
from tkinter import *

characters = "abcdefABCDEF1234!@#$"

length = 8

window = Tk()

window.title('Password Generator')

while True:
    input("Press Enter to generate new password")
    password = "".join(random.sample(characters, length))
    print(password)

label = Label (window, print(password))

label.pack(padx = 200, pady = 50)

window.mainloop()

It's hard to understand what exactly you are trying to achieve.很难理解你到底想要达到什么目的。 Since it is a password generator, based on your previous code and my assumption, I have made some changes to your code.由于它是密码生成器,根据您之前的代码和我的假设,我对您的代码进行了一些更改。 It generates and displays a new password on every button click.它会在每次单击按钮时生成并显示一个新密码。

import random
from tkinter import *

characters = "abcdefABCDEF1234!@#$"

length = 8

def generatepassword():
    password = "".join(random.sample(characters, length))
    label.config(text=password)
    
window = Tk()

window.title('Password Generator')

generatebtn = Button(window,text="Click to Generate Password",command=generatepassword)
generatebtn.pack()

label = Label (window,text="")

label.pack(padx = 200, pady = 50)

window.mainloop()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM