I'm trying to have a Label appear for 2 seconds when condition is met. User is supposed to enter 3 fields, if they do not, i dont want them to be allowed to proceed. I'm not able to delete this Label called "warnlabel" no matter which approach. Please let me know what am I doing wrong.
def get_API_KEYS(): #Main function
root = Tk()
"""...other declarations / conditions / window settings ..."""
def Save_KC_Keys(): #Button press triggers this function
if len(UE1_var.get()) == 0 or len(UE2_var.get()) == 0 or len(UE3_var.get()) == 0:
warnlabel = Label(root, text="MUST ENTER ALL 3").grid(row=1, column=3)
#root.forget(Label)
#root.after(1000, root.destroy(warnlabel))
#root.forget(warnlabel)
"""...other conditions..."""
root.mainloop()
I have tried .forget / .destroy / .after (i would prefer .after to work), however in almost every configuration i receive an error such as :
return getattr(self.tk, attr)
AttributeError: '_tkinter.tkapp' object has no attribute '_name'
root.after(1000, root.destroy(warnlabel))
TypeError: Tk.destroy() takes 1 positional argument but 2 were given
self.tk.call('wm', 'forget', window)
_tkinter.TclError: wrong # args: should be "wm option window ?arg ...?"
CodePudding user response:
Attempt to do
root.after(2000, lambda: warnlabel.destroy())
Try using it without lambda.
And also change
warnlabel = Label(root, text="MUST ENTER ALL 3").grid(row=1, column=3)
To this
warnlabel = Label(root, text="MUST ENTER ALL 3")
warnlabel.grid(row=1, column=3)