Esempio n. 1
0
def indexbox(msg="Shall I continue?", title=" ",
             choices=("Yes", "No"), image=None,
             default_choice='Yes', cancel_choice='No'):
    """
    Display a buttonbox with the specified choices.

    :param str msg: the msg to be displayed
    :param str title: the window title
    :param list choices: a list or tuple of the choices to be displayed
    :param str image: Filename of image to display
    :param str default_choice: The choice you want highlighted
      when the gui appears
    :param str cancel_choice: If the user presses the 'X' close,
      which button should be pressed
    :return: the index of the choice selected, starting from 0
    """
    reply = buttonbox(msg=msg,
                      title=title,
                      choices=choices,
                      image=image,
                      default_choice=default_choice,
                      cancel_choice=cancel_choice)
    if reply is None:
        return None
    for i, choice in enumerate(choices):
        if reply == choice:
            return i
    msg = ("There is a program logic error in the EasyGui code "
           "for indexbox.\nreply={0}, choices={1}".format(
               reply, choices))
    raise AssertionError(msg)
Esempio n. 2
0
def msgbox(msg="(Your message goes here)",
           title=" ",
           ok_button="OK",
           image=None,
           root=None):
    """
    Display a message box

    :param str msg: the msg to be displayed
    :param str title: the window title
    :param str ok_button: text to show in the button
    :param str image: Filename of image to display
    :param tk_widget root: Top-level Tk widget
    :return: the text of the ok_button
    """
    if not isinstance(ok_button, ut.basestring):
        raise AssertionError(
            "The 'ok_button' argument to msgbox must be a string.")

    return buttonbox(msg=msg,
                     title=title,
                     choices=[ok_button],
                     image=image,
                     default_choice=ok_button,
                     cancel_choice=ok_button)
Esempio n. 3
0
def indexbox(msg="Shall I continue?",
             title=" ",
             choices=("Yes", "No"),
             image=None,
             default_choice='Yes',
             cancel_choice='No'):
    """
    Display a buttonbox with the specified choices.

    :param str msg: the msg to be displayed
    :param str title: the window title
    :param list choices: a list or tuple of the choices to be displayed
    :param str image: Filename of image to display
    :param str default_choice: The choice you want highlighted
      when the gui appears
    :param str cancel_choice: If the user presses the 'X' close,
      which button should be pressed
    :return: the index of the choice selected, starting from 0
    """
    reply = buttonbox(msg=msg,
                      title=title,
                      choices=choices,
                      image=image,
                      default_choice=default_choice,
                      cancel_choice=cancel_choice)
    if reply is None:
        return None
    for i, choice in enumerate(choices):
        if reply == choice:
            return i
    msg = ("There is a program logic error in the EasyGui code "
           "for indexbox.\nreply={0}, choices={1}".format(reply, choices))
    raise AssertionError(msg)
Esempio n. 4
0
def boolbox(msg="Shall I continue?",
            title=" ",
            choices=("[T]rue", "[F]alse"),
            image=None,
            default_choice='[T]rue',
            cancel_choice='[F]alse'):
    """
    The ``boolbox()`` (boolean box) displays two buttons. Returns returns
    ``True`` if the first button is chosen. Otherwise returns ``False``.

        import easygui
        message = "What do they say?"
        title = "Romantic Question"
        if easygui.boolbox(message, title, ["They love me", "They love me not"]):
            easygui.msgbox('You should send them flowers.')
        else:
            easygui.msgbox('It was not meant to be.')

    :param str msg: The message shown in the center of the dialog window.
    :param str title: The window title text.
    :param list choices: A list or tuple of strings for the buttons' text.
    :param str image: The filename of an image to display in the dialog window.
    :param str default_choice: The text of the default selected button.
    :param str cancel_choice: If the user presses the 'X' close, which button
      should be pressed
    :return: `True` if first button pressed or dialog is cancelled, `False`
      if second button is pressed.
    """
    if len(choices) != 2:
        raise AssertionError(
            'boolbox() takes exactly 2 choices!  Consider using indexbox() instead.'
        )

    reply = buttonbox(msg=msg,
                      title=title,
                      choices=choices,
                      image=image,
                      default_choice=default_choice,
                      cancel_choice=cancel_choice)

    if reply == choices[0]:
        return True  # The first button (True) was selected.
    elif reply == choices[1]:
        return False  # The second button (False) was selected.
    elif reply is None:
        return None  # The window was closed.

    assert False, "The user selected an unexpected response."
Esempio n. 5
0
def boolbox(msg="Shall I continue?",
            title=" ",
            choices=("[Y]es", "[N]o"),
            image=None,
            default_choice='Yes',
            cancel_choice='No'):
    """
    Display a boolean msgbox.

    The returned value is calculated this way::

        if the first choice is chosen, or if the dialog is cancelled:
            returns True
        else:
            returns False

    :param str msg: the msg to be displayed
    :param str title: the window title
    :param list choices: a list or tuple of the choices to be displayed
    :param str image: Filename of image to display
    :param str default_choice: The choice you want highlighted
      when the gui appears
    :param str cancel_choice: If the user presses the 'X' close, which button
      should be pressed
    :return: True if first button pressed or dialog is cancelled, False if
      second button is pressed
    """
    if len(choices) != 2:
        raise AssertionError(
            'boolbox takes exactly 2 choices!  Consider using indexbox instead'
        )

    reply = buttonbox(msg=msg,
                      title=title,
                      choices=choices,
                      image=image,
                      default_choice=default_choice,
                      cancel_choice=cancel_choice)
    if reply is None:
        return None
    if reply == choices[0]:
        return True
    else:
        return False
Esempio n. 6
0
def indexbox(msg="Shall I continue?",
             title=" ",
             choices=("Yes", "No"),
             image=None,
             default_choice='Yes',
             cancel_choice='No'):
    """
    The ``indexbox()`` function displays a set of buttons, and returns the
    index of the selected button. For example, if you invoked index box with
    three choices (A, B, C), indexbox would return 0 if the user picked A, 1
    if he picked B, and 2 if he picked C.

        import easygui
        result = easygui.indexbox('Which door do you choose?', 'Win Prizes!', choices=['Door 1', 'Door 2', 'Door 3'])
        if result == 2:
            easygui.msgbox('You win a new car!')
        else:
            easygui.msgbox('Better luck next time.')

    :param str msg: the msg to be displayed
    :param str title: the window title
    :param list choices: a list or tuple of the choices to be displayed
    :param str image: Filename of image to display
    :param str default_choice: The choice you want highlighted
      when the gui appears
    :param str cancel_choice: If the user presses the 'X' close,
      which button should be pressed
    :return: the index of the choice selected, starting from 0
    """
    reply = buttonbox(msg=msg,
                      title=title,
                      choices=choices,
                      image=image,
                      default_choice=default_choice,
                      cancel_choice=cancel_choice)
    if reply is None:
        return None
    for i, choice in enumerate(choices):
        if reply == choice:
            return i
    msg = ("There is a program logic error in the EasyGui code "
           "for indexbox.\nreply={0}, choices={1}".format(reply, choices))
    raise AssertionError(msg)
Esempio n. 7
0
def boolbox(msg="Shall I continue?", title=" ",
            choices=("[Y]es", "[N]o"), image=None,
            default_choice='Yes', cancel_choice='No'):
    """
    Display a boolean msgbox.

    The returned value is calculated this way::

        if the first choice is chosen, or if the dialog is cancelled:
            returns True
        else:
            returns False

    :param str msg: the msg to be displayed
    :param str title: the window title
    :param list choices: a list or tuple of the choices to be displayed
    :param str image: Filename of image to display
    :param str default_choice: The choice you want highlighted
      when the gui appears
    :param str cancel_choice: If the user presses the 'X' close, which button
      should be pressed
    :return: True if first button pressed or dialog is cancelled, False if
      second button is pressed
    """
    if len(choices) != 2:
        raise AssertionError(
            'boolbox takes exactly 2 choices!  Consider using indexbox instead'
        )

    reply = buttonbox(msg=msg,
                      title=title,
                      choices=choices,
                      image=image,
                      default_choice=default_choice,
                      cancel_choice=cancel_choice)
    if reply is None:
        return None
    if reply == choices[0]:
        return True
    else:
        return False
Esempio n. 8
0
def msgbox(msg="(Your message goes here)",
           title=" ",
           ok_button="OK",
           image=None,
           root=None):
    """
    The ``msgbox()`` function displays a text message and offers an OK
    button. The message text appears in the center of the window, the title
    text appears in the title bar, and you can replace the "OK" default text
    on the button. Here is the signature::

        def msgbox(msg="(Your message goes here)", title="", ok_button="OK"):
            ....

    The clearest way to override the button text is to do it with a keyword
    argument, like this::

        easygui.msgbox("Backup complete!", ok_button="Good job!")

    Here are a couple of examples::

        easygui.msgbox("Hello, world!")

    :param str msg: the msg to be displayed
    :param str title: the window title
    :param str ok_button: text to show in the button
    :param str image: Filename of image to display
    :param tk_widget root: Top-level Tk widget
    :return: the text of the ok_button
    """
    if not isinstance(ok_button, ut.basestring):
        raise AssertionError(
            "The 'ok_button' argument to msgbox must be a string.")

    return buttonbox(msg=msg,
                     title=title,
                     choices=[ok_button],
                     image=image,
                     default_choice=ok_button,
                     cancel_choice=ok_button)
Esempio n. 9
0
def msgbox(msg="(Your message goes here)", title=" ",
           ok_button="OK", image=None, root=None):
    """
    Display a message box

    :param str msg: the msg to be displayed
    :param str title: the window title
    :param str ok_button: text to show in the button
    :param str image: Filename of image to display
    :param tk_widget root: Top-level Tk widget
    :return: the text of the ok_button
    """
    if not isinstance(ok_button, ut.basestring):
        raise AssertionError(
            "The 'ok_button' argument to msgbox must be a string.")

    return buttonbox(msg=msg,
                     title=title,
                     choices=[ok_button],
                     image=image,
                     default_choice=ok_button,
                     cancel_choice=ok_button)