How to create a self-destructing Tkinter dialog box?

M

mrstevegross

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
 
M

Martin P. Hellwig

mrstevegross said:
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.
 
J

John Posner

mrstevegross said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top