So i just made a password generator but everytime i generate a new one the label doesnt updates,it just adds a new password in the window keeping the previous ones
import random
import string
import time
from tkinter import *
def pass_generator():
length = textBox.get()
characters = list(string.ascii_letters + string.digits + "!@#$%^&*()")
password = []
display_pass = StringVar()
while len(password) < int(length):
password.append(random.choice(characters))
display_pass.set("".join(password))
print("This is your password: \n")
print("".join(password))
Label(window, textvariable=display_pass).pack()
# with open("passwords.txt", "a") as f:
# date = time.strftime("%d/%m/%Y %H:%M:%S")
# f.write(f"{date}: " + "".join(password) + "\n")
window = Tk()
window.geometry("500x150")
textBox = IntVar()
text = Label(window, text="Password length:").pack(side=LEFT)
length_entry = Entry(window, textvariable=textBox).pack(side=RIGHT)
button1 = Button(window, text="Generate", command=pass_generator).pack(side=BOTTOM)
window.mainloop()
I want to replace the current password with the new generated one but i cant get to do that