robertlugg / easygui

easygui for Python
http://easygui.readthedocs.org/en/master/
BSD 3-Clause "New" or "Revised" License
457 stars 116 forks source link

"X" button behavior limited in functionality. #83

Closed spyoungtech closed 8 years ago

spyoungtech commented 9 years ago

The "x" button behavior could benefit from improvement/bug-fixing. The keyword argument "cancel_choice" should allow you to define a string, which will be returned if the user presses the "x" button.

The "x" button appears to be limited to returning either None or False.

Returning “False” is problematic for the following case and similar cases, where pressing “x” would be the same as clicking “No” which should not be the expected result of clicking “x”

Human = easygui.ynbox(“Are you a Human?”)
If Human == True:
    easygui.msgbox(“You are a human! Welcome to the human club!”)
elif Human == False:
    easygui.msgbox(“You are not a human! Welcome to the non-human club!”)
else:
    sys.exit()

In this case and similar cases, the 'else' case will never be caught. Ideally, boolboxes, ynboxes and the like should have the option to return some value other than True or False when the 'x' button is pressed.

AT THE VERY LEAST: pressing "x" should either ALWAYS return None for any kind of box, or you should be able to explicitly define what is returned when the x button is pressed.

spyoungtech commented 9 years ago

. I was able to successfully modify the derived_boxes.py in the EasyGUI module to get the desired result of the X button always returning None, rather than False.

Where the boolbox function is defined I changed

if reply == choices[0]:
    return True
else:
    return False

TO:

if reply == choices[0]:
    return True
elif reply == choices[1]:
    return False
else:
    return None

Now, I am able to distinguish when the "x" button is pressed, versus when "No" being selected in a ynbox (and any other box that wraps a boolbox)

robertlugg commented 8 years ago

confirmed. Good idea.

robertlugg commented 8 years ago

I finally got around to making this change.