Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1579

Python • Re: tkinter after() problems

$
0
0
Hope I understood correctly
- you have a password tkinter.Entry and an infopad tkinter.Label.
- the infopad shows something like "enter a password"
- the password is checked and the infopad shows whether password is good or bad.
- 20sec after the check the infopad should display the initial text "enter a password".

My solution would be

Code:

import tkinterINFOTEXT_DEFAULT = "provide a password"def infopad_update():    print("infopad_update")    infopad.config(text=INFOTEXT_DEFAULT)    def password_evaluate(evt):    global infopad_update_action        # delete pending infopad_update_action    if infopad_update_action is not None:        root.after_cancel(infopad_update_action)            if password.get() == "123":        infopad.config(text='correct password')    else:        infopad.config(text='wrong password')    # delete data from entry field    password.delete(0, tkinter.END)        # trigger a text change on the infopad    # keep the action in order to cancel it eventually    infopad_update_action = root.after(20_000, infopad_update)root = tkinter.Tk()# the tkinter.after() result, needed to cancel actions infopad_update_action = Noneinfopad = tkinter.Label(root, text=INFOTEXT_DEFAULT)infopad.pack()password = tkinter.Entry(root, show="*", width =5)password.pack()password.bind("<Return>", password_evaluate)root.mainloop()

Statistics: Posted by ghp — Sun Nov 16, 2025 5:20 pm



Viewing all articles
Browse latest Browse all 1579

Trending Articles