Closing dialog window in Tkinter

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Svennglenn

    #1

    Closing dialog window in Tkinter

    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(sel f):
    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.

  • Harlin Seritt

    #2
    Re: Closing dialog window in Tkinter

    You can add this:

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

    That will kill the Toplevel window.

    Cheers,

    Harlin Seritt

    Comment

    • Svennglenn

      #3
      Re: Closing dialog window in Tkinter


      Harlin Seritt wrote:[color=blue]
      > You can add this:
      >
      > button = Button(top, text="Close Me", command=top.des troy)
      > button.pack()
      >
      > That will kill the Toplevel window.
      >
      > Cheers,
      >
      > Harlin Seritt[/color]

      Thank you, it worked great :)

      Comment

      • Harlin Seritt

        #4
        Re: Closing dialog window in Tkinter

        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(mas ter)

        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

        Comment

        Working...