Tkinter: Making a window disappear

Claus Tondering claus.tondering at gmail.com
Mon Oct 9 05:02:33 EDT 2006


I am trying to make a Tkinter main window appear and disappear, but I
have problems with that.

Here is a small code sample:

    class MyDialog(Frame):
        def __init__(self):
            Frame.__init__(self, None)
            Label(self, text="Hello").pack()
            Button(self, text="OK", command=self.ok).pack()
            self.grid()

        def ok(self):
            self.destroy()
            self.quit()

    MyDialog().mainloop()
    print "Now waiting 5 seconds"
    time.sleep(5)
    MyDialog().mainloop()

The first mainloop() shows the dialog nicely, and I press the "OK"
button. The system then sleeps for 5 seconds, and a new dialog is
displayed. This is all very nice.

But during the 5 seconds of sleeping, remnants of the old window are
still visible. It is not redrawn, but it just lies there as an ugly box
on the display. I thought that destroy()/quit() would completely remove
the window, but obviously I am wrong.

What should I do instead?

--
Claus Tondering




More information about the Python-list mailing list