Python Password Generator with TKInter

544 Views Asked by At

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

There are 1 best solutions below

0
On

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