views:

534

answers:

2

I've created a very simple app, which presents an easygui entrybox() and continues to loop this indefinitely as it receives user input.

I can quit the program using the Cancel button as this returns None, but I would also like to be able to use the standard 'close' button to quit the program. (ie. top right of a Windows window, top left of a Mac window) This button currently does nothing.

Taking a look at the easygui module I found this line:

root.protocol('WM_DELETE_WINDOW', denyWindowManagerClose )

This would seem to be the culprit. I'm no TKinter expert but I could probably work out how to alter this handler to act the way I want.

However, as I'd rather not mess about with the easygui module, Is there a way to override this behavior from my main script, and have the close button either close the program outright or return None?

A: 

I don't know right now, but have you tried something like this?:

root.protocol('WM_DELETE_WINDOW',  self.quit)

or

root.protocol('WM_DELETE_WINDOW',  self.destroy)

I haven't tried, but google something like "Tkinter protocol WM_DELETE_WINDOW"

Angel
something along those line would probably work, but wouldn't it require altering the easygui module? This may in fact be the only way to do it, but I'm interested to see if there is any other way to do it.
nakedfanatic
+3  A: 

It would require altering the easygui module, yes. I will get it modified!

** I have sent in a e-mail to the EasyGUI creator explaning this [12:12 PM, January 23/09]

** I just want to say that the possibility of this change happening - if at all, which I doubt - is very tiny. You see, EasyGUI is intended to be a simple, discrete way to create GUIs. I think that this addition wouldn't help any, especially since the interface is very sequential, so it would be confusing to new users. [12:19 PM, January 23/09]

** The EasyGUI creator said this in reply to my e-mail:

An easygui dialog should never exit the application -- it should pass back a value to the caller and let the caller decide what to do.

But this is an interesting idea. Rather than simply ignoring a click on the "close" icon, easygui boxes could return the same value that a click on the "cancel" button would return. I'll meditate on this.

-- Steve Ferg

I think that this is progress at least. [2:40 PM, January 23/09]

kylebrooks
This is excellent. I hadn't thought if emailing the creator! I agree that the close button should not close the program outright, but it would be nice if it mirrored the behavior of the cancel button.
nakedfanatic