I am doing saving jobs when user presses my "Close" button in GUI environment written in Python with Tkinter library. However, if user pushes the X button on top the window to close the window, I can't do anything. How can I control -be aware of- this button?
I found a reference on Tkinter here. It's not perfect, but covers nearly everything I ever needed. I figure section 30.3 (Event types) helps, it tells us that there's a "Destroy" event for widgets. I suppose .bind()ing your saving jobs to that event of your main window should do the trick.
You could also call mainwindow.overrideredirect(True) (section 24), which disables minimizing, resizing and closing via the buttons in the title bar.
It sounds as if your save window should be modal. See: http://en.m.wikipedia.org/wiki/Modal_window
If this is a basic save window, why are you reinventing the wheel?
Tk has a tkFileDialog for this purpose: http://tkinter.unpythonic.net/wiki/tkFileDialog
EDIT: After rereading your question, I think I understand what you mean - you want to override the default behavior of destroying the window.
What about:
# root is your root window
root.protocol('WM_DELETE_WINDOW', doSomething)
def doSomething():
# check if saving
# if not:
root.destroy()
This way, you can intercept the destroy() call when someone closes the window (by any means) and do what you like.
The command you are looking for is wm_protocol, giving it "WM_DELETE_WINDOW" as the protocol to bind to. It lets you define a procedure to call when the window manager closes the window (which is what happens when you click the [x]).