Python Forum
[Tkinter] Remove label after x seconds
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Remove label after x seconds
#1
I've got a Label that pops up saying "Saved" after the user presses the "Save" button.

Is there any way to make this "Saved" Label disappear after say 8s?

Thanks
Reply
#2
You can use an after to destroy the label after a certain amount of milliseconds.
import tkinter as tk


class App(tk.Tk):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.btn = tk.Button(self, text="Save", command=self.on_btn)
        self.btn.pack(padx=5, pady=5)

    def on_btn(self):
        label = tk.Label(self, text='Saved')
        label.pack(padx=5, pady=5)
        self.after(8000, label.destroy)


if __name__ == '__main__':
    app = App()
    app.mainloop()
Reply
#3
I opened a word document, edited the text and saved the file. The status bar says "somefile.docx saved to this PC". 10 minutes from now it will say "somefile.docx saved to this PC". An hour from now it will say this. It will continue to say this until I edit the text, then it the text in the status bar changes to "somefile.docx". The status bar information is always visible and always up-to-date. There is no status information that appears for 8 seconds then is gone.

What you are trying to do is bad user interface design. Information may have an expiration date, but the expiration date is unlikely to be 8 seconds. If you think it is important to tell the user that changes to their data is saved, display that information until it is no longer true. Word stops telling me my document is saved when the open document was edited after the last save.

Or are is your message meant to notify the user that a save operation occurred? Displaying a label for 8 seconds is not a good way to inform the user that an event occurred. A message window is a better choice. A message window is better than a label because it forces the user to acknowledge the notification. What if the user doesn't notice the label, or worse, doesn't notice the label until it disappears? Now your user is uninformed and possibly quite concerned that some important information disappeared before it was read and understood. A message window demands that the user acknowledge the information was read and understood before additional actions can be performed.
Reply
#4
Thank you for your responses... it's been good to learn about 'after' but I also agree with the use of a message window. I'm going to go that route.

Thanks guys!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Change Label Every 5 Seconds gw1500se 4 6,891 May-26-2020, 05:32 PM
Last Post: gw1500se

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020