Shengen
Shengen

Reputation: 73

How to close IDLE window which is opened by Tkinter.Tk()

From my last question, how to add the selected files from dialog window to a dictionary?, I opened an another IDLE window, which has nothing (no menu and command)

   import Tkinter,tkFileDialog
   root = Tkinter.Tk()

How could I close this window?

Upvotes: 0

Views: 420

Answers (2)

Peter Varo
Peter Varo

Reputation: 12150

As @inspectorG4dget says, you can use root.destroy(), but that is for destroying a widget and all it's children. If you mean by "closing the window" that you actually want to shut down your program, you should use root.quit().

So for that I created you an example, where I binded the ESC button to the quitter function:

import Tkinter as tk

def quit(obj):
    obj.quit()

root = tk.Tk()
root.bind('<Escape>', lambda e: quit(root))
root.mainloop()

So after you program is running, if you hit the ESC it will quit.

Anyway, for further info RTFM: Tk Interface Book

Upvotes: 0

inspectorG4dget
inspectorG4dget

Reputation: 113945

This was originally a comment, but it seems to be what you need, so:

I'm not 100% sure, but from what I can gather from your post, I think what you're looking for is root.destroy()

Upvotes: 1

Related Questions