1

I am using EasyGUI as part of a small program I am writing. In it, I am using the IntegerBox "function".

Part of the parameters of this function is the lowerbound and the upperbound (the limits of the value entered). If the value is under the lowerbound or if it exceeds the upperbound, the program raises an error.

Only for this program, I want to remove the lowerbound/upperbound--- so it is possible to put any number in.

My code is:

import easygui as eg
numMin=eg.integerbox(msg="What is the minimum value of the numbers?"
                   , title="Random Number Generator"
                   , default=0
                   , lowerbound=
                   , upperbound=
                   , image=None
                   , root=None
                   )

I don't have anything entered yet, because I don't know what to put. Any input would be greatly appreciated. Thanks!

Rushy Panchal
  • 16,979
  • 16
  • 61
  • 94

1 Answers1

2

When all else fails, trying reading the documentation (that is, if there is any ;-).

With EasyGui there is, although it's a separate download, the easygui-docs-0.97.zip file, shown on this webpage. Here's what it says in the API section for the integerbox() function:

screenshot of easygui integer box documentation

So, to answer your question, no, there doesn't appear to be a way to disable the bounds-checking the module's integerbox() does.

Update: Here's a new function you can add to the module that doesn't do bounds-checking at all nor does it accept bounds arguments (so it's not strictly call-compatible with the stock version). If you put it in, be sure to also add its name, 'integerbox2', to the definition of the __all__ list near the top of the module's script file.

If you would like to minimize changes to the easygui module's script itself in case there's a future update, you instead could put the new function in a separate .py file and then add an import integerbox2 near the top of easygui.py (plus another line to add it to __all__).

Here's the additional function:

#-------------------------------------------------------------------
# integerbox2 - like integerbox(), but without bounds checking.
#-------------------------------------------------------------------
def integerbox2(msg=""
               , title=" "
               , default=""
               , image=None
               , root=None):
    """
    Show a box in which a user can enter an integer.

    In addition to arguments for msg and title, this function accepts
    an integer argument for "default".

    The default argument may be None.

    When the user enters some text, the text is checked to verify that it
    can be converted to an integer, **no bounds checking is done**.

    If it can be, the integer (not the text) is returned.

    If it cannot, then an error msg is displayed, and the integerbox is
    redisplayed.

    If the user cancels the operation, None is returned.

    :param str msg: the msg to be displayed
    :param str title: the window title
    :param str default: The default value to return
    :param str image: Filename of image to display
    :param tk_widget root: Top-level Tk widget
    :return: the integer value entered by the user

    """
    if not msg:
        msg = "Enter an integer value"

    # Validate the arguments and convert to integers
    exception_string = ('integerbox "{0}" must be an integer.  '
                        'It is >{1}< of type {2}')
    if default:
        try:
            default=int(default)
        except ValueError:
            raise ValueError(exception_string.format('default', default,
                                                     type(default)))

    while 1:
        reply = enterbox(msg, title, str(default), image=image, root=root)
        if reply is None:
            return None
        try:
            reply = int(reply)
        except:
            msgbox('The value that you entered:\n\t"{}"\n'
                   'is not an integer.'.format(reply), "Error")
            continue
        # reply has passed validation check, it is an integer.
        return reply
martineau
  • 119,623
  • 25
  • 170
  • 301
  • I don't see how that helps... Only the "default" parameter can be None; not anything else. I've tried putting None for both lowerbound and upperbound parameters, and I get an error because it is a non-integer value. – Rushy Panchal Nov 13 '12 at 19:51
  • RTFM...which says that the `default`, `lowerbound`, and `upperbound` arguments must be integer. You realize `None` is not an integer, right? Also, if you take a look at the source code, you'll see that all the arguments in the function definition do indeed have the documented default values. – martineau Nov 13 '12 at 20:05
  • 1
    In Python integers don't really have any limits, so if you really want absolutely no limit checking modify the source provided (or add a new function derived from the one provided) that does what you want -- which in this cause would be check to see if the arguments are `None` and skipping any bounds tests. – martineau Nov 13 '12 at 20:13
  • How would that code go? I know how to start it off, but I'm not sure how to skip the bound tests. – Rushy Panchal Nov 14 '12 at 14:49
  • 1
    @F3AR3DLEGEND: See edit and note added to my answer. As you can see I just ripped out the bounds checking which was easier to do than make it optional. Let me also apologize slightly for my initial answer and comments which assumed that the documentation available was completely accurate. ;-) – martineau Nov 14 '12 at 17:11
  • Ooh, making a new box for it. I'll do that. Thanks for all the help and sorry for the trouble :3 I still don't do very well with my programming... learning the basics :) – Rushy Panchal Nov 15 '12 at 01:40
  • 1
    One of the many nice things about open source software is that you can change it with relative ease -- assuming you can figure-out how to do it, that is. Happy programming! – martineau Nov 15 '12 at 01:57