How to create a self-destructing Tkinter dialog box?

Discussion in 'Python' started by mrstevegross, Dec 16, 2009.

  1. mrstevegross

    mrstevegross Guest

    Ok, I would like to put together a Python/Tkinter dialog box that
    displays a simple message and self-destructs after N seconds. Is there
    a simple way to do this?

    Thanks,

    --Steve
     
    mrstevegross, Dec 16, 2009
    #1
    1. Advertising

  2. mrstevegross wrote:
    > Ok, I would like to put together a Python/Tkinter dialog box that
    > displays a simple message and self-destructs after N seconds. Is there
    > a simple way to do this?
    >
    > Thanks,
    >
    > --Steve


    Just, thinking aloud, I probably would do something like registering the
    [place|grid|pack]_forget() function by using the alarm callback
    'after()' function of that frame.

    --
    MPH
    http://blog.dcuktec.com
    'If consumed, best digested with added seasoning to own preference.'
     
    Martin P. Hellwig, Dec 17, 2009
    #2
    1. Advertising

  3. mrstevegross

    John Posner Guest

    On Thu, 17 Dec 2009 02:09:03 -0500, Martin P. Hellwig
    <> wrote:

    > mrstevegross wrote:
    >> Ok, I would like to put together a Python/Tkinter dialog box that
    >> displays a simple message and self-destructs after N seconds. Is there
    >> a simple way to do this?
    >> Thanks,
    >> --Steve

    >
    > Just, thinking aloud, I probably would do something like registering the
    > [place|grid|pack]_forget() function by using the alarm callback
    > 'after()' function of that frame.
    >


    Yup, after() is your friend:

    #---------------------------
    from Tkinter import *
    from functools import partial

    def RemoveWindow(win):
    win.destroy()

    # root window
    root = Tk()
    Label(root, text="this is the main window").pack()

    # another top-level window, to be removed in 2 seconds
    top = Toplevel()
    Label(top, text="this is the window to be removed").pack()
    root.after(2000, partial(RemoveWindow, top))

    # go
    root.mainloop()
    #---------------------------

    HTH,
    John
     
    John Posner, Dec 17, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ralf W. Grosse-Kunstleve
    Replies:
    16
    Views:
    596
    Lonnie Princehouse
    Jul 11, 2005
  2. Ralf W. Grosse-Kunstleve
    Replies:
    18
    Views:
    602
    Bengt Richter
    Jul 11, 2005
  3. Ralf W. Grosse-Kunstleve
    Replies:
    2
    Views:
    409
    Dan Sommers
    Jul 12, 2005
  4. kvt

    self destructing programs

    kvt, Dec 9, 2007, in forum: C Programming
    Replies:
    9
    Views:
    307
    David Thompson
    Dec 24, 2007
  5. kvt
    Replies:
    8
    Views:
    358
    James Kanze
    Dec 11, 2007
Loading...

Share This Page