+ 1
Changing Text In tkinter
I Was Working On A GUI Program To Generate A Random Password: from tkinter import * t = Tk() t.resizable(0, 0) def gene(): import random from string import ascii_letters,digits letters = list(ascii_letters+digits) password = "" c = random.randrange(8,17) for i in range(c): password = password + random.choice(letters) statement = f"Your New Password Is:\n{password}\n" return statement l = Label(t, text=gene()).pack() b = Button(t, text="Click To Generate Another Password", command=gene()).pack() t.mainloop() My Problem Is That When I Click The Button,It Doesn't Generate Another Password,The Text Remains As It Is. How Can I Fix That?
1 Réponse
+ 1
It is generating the password but it is not updating the text inside the label. Try using the label inside the function
first store that password inside any variable then assign it to text attribute of label widget(Label should be inside your fuction)