I am trying to learn python and want to make a password generator with a tkinter display. When I try to use StringVar to generate a password by clicking a button, it doesn't work and the label shows me the same text.
import random as rd
import string as stg
from tkinter import *
def generatePassword(size):
min=size
max=size
string_format = stg.ascii_letters + stg.digits
generated_password = "".join(rd.choice(string_format) for x in range(rd.randint(min, max)))
with open("pwd_logs.txt","a") as f:
f.write(f"{generated_password}\r")
f.close()
string_var.set(generated_password)
color = ""
screen = Tk()
screen.title("Password generator")
screen.config(bg=color)
screen.geometry("200x200")
string_var = StringVar()
generation_b = Button(screen,text="generate", command=generatePassword(15)).pack()
label = Label(screen,text="Password", bg=color, textvariable=string_var).pack()
screen.mainloop()
I also need to configure the label so that the text "password" appears when the program starts instead of the password.