简体   繁体   中英

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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