Closing dialog window in Tkinter

S

Svennglenn

Hi

I'm creating a program in Tkinter and I would need
help to create a "close button" for dialog windows.

One of my typical dialog windows look like this:

def show_window(self):
top = Toplevel()

Label(top, text="Some text").pack()
Label(top, text="Some more text").pack()


So what code do i need to insert to create a button that
can close this window? If you need to look at some more
code from the program to be sure please till me.
 
H

Harlin Seritt

You can add this:

button = Button(top, text="Close Me", command=top.destroy)
button.pack()

That will kill the Toplevel window.

Cheers,

Harlin Seritt
 
S

Svennglenn

Harlin said:
You can add this:

button = Button(top, text="Close Me", command=top.destroy)
button.pack()

That will kill the Toplevel window.

Cheers,

Harlin Seritt

Thank you, it worked great :)
 
H

Harlin Seritt

Do you need this toplevel window to not be iconified--where it shows up
as a separate window? You can also do this:

def new_window(self, master):
t = Toplevel()
t.transient(master)

etc...

Svennglen, I put this in here because most likely you're next question
may be, how in the world do I make a modal window? I believe it was my
next question after I finally figured out how to kill a child window
without wiping out the entire app ;-). Check out Frederik Lundh's
tutorial:

http://www.pythonware.com/library/tkinter/introduction/

You can now buy a PDF form of John Grayson's Python and Tkinter
Programming from Manning Publications. I won't provide the link so that
no one will think I'm spamming :)-). Grayson's book is essential
reading if you are to write any serious apps with Tkinter.

Good luck,

Harlin
 

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

No members online now.

Forum statistics

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

Latest Threads

Top