跳转至

Messagebox

ttkbootstrap.dialogs.dialogs.Messagebox

This class contains various static methods that show popups with a message to the end user with various arrangments of buttons and alert options.

ok(message, title=' ', alert=False, parent=None, **kwargs) staticmethod

Display a modal dialog box with an OK button and and optional bell alert.

Parameters:

Name Type Description Default
message str

A message to display in the message box.

required
title str

The string displayed as the title of the messagebox. This option is ignored on Mac OS X, where platform guidelines forbid the use of a title on this kind of dialog.

' '
alert bool

Specified whether to ring the display bell.

False
parent Union[Window, Toplevel]

Makes the window the logical parent of the message box. The message box is displayed on top of its parent window.

None
**kwargs Dict

Other optional keyword arguments.

{}
Source code in ttkbootstrap/dialogs/dialogs.py
@staticmethod
def ok(message, title=" ", alert=False, parent=None, **kwargs):
    """Display a modal dialog box with an OK button and and optional
    bell alert.

    ![](../../assets/dialogs/messagebox-ok.png)

    Parameters:

        message (str):
            A message to display in the message box.

        title (str):
            The string displayed as the title of the messagebox. This
            option is ignored on Mac OS X, where platform guidelines
            forbid the use of a title on this kind of dialog.

        alert (bool):
            Specified whether to ring the display bell.

        parent (Union[Window, Toplevel]):
            Makes the window the logical parent of the message box. The
            message box is displayed on top of its parent window.

        **kwargs (Dict):
            Other optional keyword arguments.
    """
    dialog = MessageDialog(
        title=title,
        message=message,
        parent=parent,
        alert=alert,
        buttons=["OK:primary"],
        localize=True,
        **kwargs,
    )
    if "position" in kwargs:
        position = kwargs.pop("position")
    else:
        position = None
    dialog.show(position)

okcancel(message, title=' ', alert=False, parent=None, **kwargs) staticmethod

Displays a modal dialog box with OK and Cancel buttons and return the symbolic name of the button pressed.

Parameters:

Name Type Description Default
message str

A message to display in the message box.

required
title str

The string displayed as the title of the messagebox. This option is ignored on Mac OS X, where platform guidelines forbid the use of a title on this kind of dialog.

' '
alert bool

Specified whether to ring the display bell.

False
parent Union[Window, Toplevel]

Makes the window the logical parent of the message box. The message box is displayed on top of its parent window.

None
**kwargs Dict

Other optional keyword arguments.

{}

Returns:

Type Description
Union[str, None]

The symbolic name of the button pressed, or None if the window is closed without pressing a button.

Source code in ttkbootstrap/dialogs/dialogs.py
@staticmethod
def okcancel(message, title=" ", alert=False, parent=None, **kwargs):
    """Displays a modal dialog box with OK and Cancel buttons and
    return the symbolic name of the button pressed.

    ![](../../assets/dialogs/messagebox-ok-cancel.png)

    Parameters:

        message (str):
            A message to display in the message box.

        title (str):
            The string displayed as the title of the messagebox. This
            option is ignored on Mac OS X, where platform guidelines
            forbid the use of a title on this kind of dialog.

        alert (bool):
            Specified whether to ring the display bell.

        parent (Union[Window, Toplevel]):
            Makes the window the logical parent of the message box. The
            message box is displayed on top of its parent window.

        **kwargs (Dict):
            Other optional keyword arguments.

    Returns:

        Union[str, None]:
            The symbolic name of the button pressed, or None if the
            window is closed without pressing a button.
    """
    dialog = MessageDialog(
        title=title,
        message=message,
        parent=parent,
        alert=alert,
        localize=True,
        **kwargs,
    )
    if "position" in kwargs:
        position = kwargs.pop("position")
    else:
        position = None
    dialog.show(position)
    return dialog.result

retrycancel(message, title=' ', alert=False, parent=None, **kwargs) staticmethod

Display a modal dialog box with RETRY and Cancel buttons; returns the symbolic name of the button pressed.

Parameters:

Name Type Description Default
message str

A message to display in the message box.

required
title str

The string displayed as the title of the messagebox. This option is ignored on Mac OS X, where platform guidelines forbid the use of a title on this kind of dialog.

' '
alert bool

Specified whether to ring the display bell.

False
parent Union[Window, Toplevel]

Makes the window the logical parent of the message box. The message box is displayed on top of its parent window.

None
**kwargs Dict

Other optional keyword arguments.

{}

Returns:

Type Description
Union[str, None]

The symbolic name of the button pressed, or None if the window is closed without pressing a button.

Source code in ttkbootstrap/dialogs/dialogs.py
@staticmethod
def retrycancel(message, title=" ", alert=False, parent=None, **kwargs):
    """Display a modal dialog box with RETRY and Cancel buttons;
    returns the symbolic name of the button pressed.

    ![](../../assets/dialogs/messagebox-retry-cancel.png)

    Parameters:

        message (str):
            A message to display in the message box.

        title (str):
            The string displayed as the title of the messagebox. This
            option is ignored on Mac OS X, where platform guidelines
            forbid the use of a title on this kind of dialog.

        alert (bool):
            Specified whether to ring the display bell.

        parent (Union[Window, Toplevel]):
            Makes the window the logical parent of the message box. The
            message box is displayed on top of its parent window.

        **kwargs (Dict):
            Other optional keyword arguments.

    Returns:

        Union[str, None]:
            The symbolic name of the button pressed, or None if the
            window is closed without pressing a button.
    """
    dialog = MessageDialog(
        title=title,
        message=message,
        parent=parent,
        alert=alert,
        buttons=["Cancel", "Retry:primary"],
        localize=True,
        **kwargs,
    )
    if "position" in kwargs:
        position = kwargs.pop("position")
    else:
        position = None
    dialog.show(position)
    return dialog.result

show_error(message, title=' ', parent=None, alert=True, **kwargs) staticmethod

Display a modal dialog box with an OK button and an error icon. Also will ring the display bell.

Parameters:

Name Type Description Default
message str

A message to display in the message box.

required
title str

The string displayed as the title of the messagebox. This option is ignored on Mac OS X, where platform guidelines forbid the use of a title on this kind of dialog.

' '
parent Union[Window, Toplevel]

Makes the window the logical parent of the message box. The message box is displayed on top of its parent window.

None
alert bool

Specified whether to ring the display bell.

True
**kwargs Dict

Other optional keyword arguments.

{}
Source code in ttkbootstrap/dialogs/dialogs.py
@staticmethod
def show_error(message, title=" ", parent=None, alert=True, **kwargs):
    """Display a modal dialog box with an OK button and an
    error icon. Also will ring the display bell.

    ![](../../assets/dialogs/messagebox-show-error.png)

    Parameters:

        message (str):
            A message to display in the message box.

        title (str):
            The string displayed as the title of the messagebox. This
            option is ignored on Mac OS X, where platform guidelines
            forbid the use of a title on this kind of dialog.

        parent (Union[Window, Toplevel]):
            Makes the window the logical parent of the message box. The
            message box is displayed on top of its parent window.

        alert (bool):
            Specified whether to ring the display bell.

        **kwargs (Dict):
            Other optional keyword arguments.
    """
    dialog = MessageDialog(
        message=message,
        title=title,
        parent=parent,
        buttons=["OK:primary"],
        icon=Icon.error,
        alert=alert,
        localize=True,
        **kwargs,
    )
    if "position" in kwargs:
        position = kwargs.pop("position")
    else:
        position = None
    dialog.show(position)

show_info(message, title=' ', parent=None, alert=False, **kwargs) staticmethod

Display a modal dialog box with an OK button and an INFO icon.

Parameters:

Name Type Description Default
message str

A message to display in the message box.

required
title str

The string displayed as the title of the messagebox. This option is ignored on Mac OS X, where platform guidelines forbid the use of a title on this kind of dialog.

' '
parent Union[Window, Toplevel]

Makes the window the logical parent of the message box. The message box is displayed on top of its parent window.

None
alert bool

Specified whether to ring the display bell.

False
**kwargs Dict

Other optional keyword arguments.

{}
Source code in ttkbootstrap/dialogs/dialogs.py
@staticmethod
def show_info(message, title=" ", parent=None, alert=False, **kwargs):
    """Display a modal dialog box with an OK button and an INFO
    icon.

    ![](../../assets/dialogs/messagebox-show-info.png)

    Parameters:

        message (str):
            A message to display in the message box.

        title (str):
            The string displayed as the title of the messagebox. This
            option is ignored on Mac OS X, where platform guidelines
            forbid the use of a title on this kind of dialog.

        parent (Union[Window, Toplevel]):
            Makes the window the logical parent of the message box. The
            message box is displayed on top of its parent window.

        alert (bool):
            Specified whether to ring the display bell.

        **kwargs (Dict):
            Other optional keyword arguments.
    """
    dialog = MessageDialog(
        message=message,
        title=title,
        alert=alert,
        parent=parent,
        buttons=["OK:primary"],
        icon=Icon.info,
        localize=True,
        **kwargs
    )
    if "position" in kwargs:
        position = kwargs.pop("position")
    else:
        position = None
    dialog.show(position)

show_question(message, title=' ', parent=None, buttons=['No:secondary', 'Yes:primary'], alert=True, **kwargs) staticmethod

Display a modal dialog box with yes, no buttons and a question icon. Also will ring the display bell. You may also change the button scheme using the buttons parameter.

Parameters:

Name Type Description Default
message str

A message to display in the message box.

required
title str

The string displayed as the title of the messagebox. This option is ignored on Mac OS X, where platform guidelines forbid the use of a title on this kind of dialog.

' '
parent Union[Window, Toplevel]

Makes the window the logical parent of the message box. The message box is displayed on top of its parent window.

None
buttons List[str]

A list of buttons to appear at the bottom of the popup messagebox. The buttons can be a list of strings which will define the symbolic name and the button text. ['OK', 'Cancel']. Alternatively, you can assign a bootstyle to each button by using the colon to separate the button text and the bootstyle. If no colon is found, then the style is set to 'primary' by default. ['Yes:success','No:danger'].

['No:secondary', 'Yes:primary']
alert bool

Specified whether to ring the display bell.

True
**kwargs Dict

Other optional keyword arguments.

{}

Returns:

Type Description
Union[str, None]

The symbolic name of the button pressed, or None if the window is closed without pressing a button.

Source code in ttkbootstrap/dialogs/dialogs.py
@staticmethod
def show_question(
    message,
    title=" ",
    parent=None,
    buttons=["No:secondary", "Yes:primary"],
    alert=True,
    **kwargs,
):
    """Display a modal dialog box with yes, no buttons and a
    question icon. Also will ring the display bell. You may also
    change the button scheme using the `buttons` parameter.

    ![](../../assets/dialogs/messagebox-show-question.png)

    Parameters:

        message (str):
            A message to display in the message box.

        title (str):
            The string displayed as the title of the messagebox. This
            option is ignored on Mac OS X, where platform guidelines
            forbid the use of a title on this kind of dialog.

        parent (Union[Window, Toplevel]):
            Makes the window the logical parent of the message box. The
            message box is displayed on top of its parent window.

        buttons (List[str]):
            A list of buttons to appear at the bottom of the popup
            messagebox. The buttons can be a list of strings which
            will define the symbolic name and the button text.
            `['OK', 'Cancel']`. Alternatively, you can assign a
            bootstyle to each button by using the colon to separate the
            button text and the bootstyle. If no colon is found, then
            the style is set to 'primary' by default.
            `['Yes:success','No:danger']`.

        alert (bool):
            Specified whether to ring the display bell.

        **kwargs (Dict):
            Other optional keyword arguments.

    Returns:

        Union[str, None]:
            The symbolic name of the button pressed, or None if the
            window is closed without pressing a button.
    """
    dialog = MessageDialog(
        message=message,
        title=title,
        parent=parent,
        buttons=buttons,
        icon=Icon.question,
        alert=alert,
        localize=True,
        **kwargs,
    )
    if "position" in kwargs:
        position = kwargs.pop("position")
    else:
        position = None
    dialog.show(position)
    return dialog.result

show_warning(message, title=' ', parent=None, alert=True, **kwargs) staticmethod

Display a modal dialog box with an OK button and a warning icon. Also will ring the display bell.

Parameters:

Name Type Description Default
message str

A message to display in the message box.

required
title str

The string displayed as the title of the messagebox. This option is ignored on Mac OS X, where platform guidelines forbid the use of a title on this kind of dialog.

' '
parent Union[Window, Toplevel]

Makes the window the logical parent of the message box. The message box is displayed on top of its parent window.

None
alert bool

Specified whether to ring the display bell.

True
**kwargs Dict

Other optional keyword arguments.

{}
Source code in ttkbootstrap/dialogs/dialogs.py
@staticmethod
def show_warning(message, title=" ", parent=None, alert=True, **kwargs):
    """Display a modal dialog box with an OK button and a
    warning icon. Also will ring the display bell.

    ![](../../assets/dialogs/messagebox-show-warning.png)

    Parameters:

        message (str):
            A message to display in the message box.

        title (str):
            The string displayed as the title of the messagebox. This
            option is ignored on Mac OS X, where platform guidelines
            forbid the use of a title on this kind of dialog.

        parent (Union[Window, Toplevel]):
            Makes the window the logical parent of the message box. The
            message box is displayed on top of its parent window.

        alert (bool):
            Specified whether to ring the display bell.

        **kwargs (Dict):
            Other optional keyword arguments.
    """
    dialog = MessageDialog(
        message=message,
        title=title,
        parent=parent,
        buttons=["OK:primary"],
        icon=Icon.warning,
        alert=alert,
        localize=True,
        **kwargs,
    )
    if "position" in kwargs:
        position = kwargs.pop("position")
    else:
        position = None
    dialog.show(position)

yesno(message, title=' ', alert=False, parent=None, **kwargs) staticmethod

Display a modal dialog box with YES and NO buttons and return the symbolic name of the button pressed.

Parameters:

Name Type Description Default
message str

A message to display in the message box.

required
title str

The string displayed as the title of the messagebox. This option is ignored on Mac OS X, where platform guidelines forbid the use of a title on this kind of dialog.

' '
alert bool

Specified whether to ring the display bell.

False
parent Union[Window, Toplevel]

Makes the window the logical parent of the message box. The message box is displayed on top of its parent window.

None
**kwargs Dict

Other optional keyword arguments.

{}

Returns:

Type Description
Union[str, None]

The symbolic name of the button pressed, or None if the window is closed without pressing a button.

Source code in ttkbootstrap/dialogs/dialogs.py
@staticmethod
def yesno(message, title=" ", alert=False, parent=None, **kwargs):
    """Display a modal dialog box with YES and NO buttons and return
    the symbolic name of the button pressed.

    ![](../../assets/dialogs/messagebox-yes-no.png)

    Parameters:

        message (str):
            A message to display in the message box.

        title (str):
            The string displayed as the title of the messagebox. This
            option is ignored on Mac OS X, where platform guidelines
            forbid the use of a title on this kind of dialog.

        alert (bool):
            Specified whether to ring the display bell.

        parent (Union[Window, Toplevel]):
            Makes the window the logical parent of the message box. The
            message box is displayed on top of its parent window.

        **kwargs (Dict):
            Other optional keyword arguments.

    Returns:

        Union[str, None]:
            The symbolic name of the button pressed, or None if the
            window is closed without pressing a button.
    """
    dialog = MessageDialog(
        title=title,
        message=message,
        parent=parent,
        buttons=["No", "Yes:primary"],
        alert=alert,
        localize=True,
        **kwargs,
    )
    if "position" in kwargs:
        position = kwargs.pop("position")
    else:
        position = None
    dialog.show(position)
    return dialog.result

yesnocancel(message, title=' ', alert=False, parent=None, **kwargs) staticmethod

Display a modal dialog box with YES, NO, and Cancel buttons, and return the symbolic name of the button pressed.

Parameters:

Name Type Description Default
message str

A message to display in the message box.

required
title str

The string displayed as the title of the messagebox. This option is ignored on Mac OS X, where platform guidelines forbid the use of a title on this kind of dialog.

' '
alert bool

Specified whether to ring the display bell.

False
parent Union[Window, Toplevel]

Makes the window the logical parent of the message box. The message box is displayed on top of its parent window.

None
**kwargs Dict

Optional keyword arguments.

{}

Returns:

Type Description
Union[str, None]

The symbolic name of the button pressed, or None if the window is closed without pressing a button.

Source code in ttkbootstrap/dialogs/dialogs.py
@staticmethod
def yesnocancel(message, title=" ", alert=False, parent=None, **kwargs):
    """Display a modal dialog box with YES, NO, and Cancel buttons,
    and return the symbolic name of the button pressed.

    ![](../../assets/dialogs/messagebox-yes-no-cancel.png)

    Parameters:

        message (str):
            A message to display in the message box.

        title (str):
            The string displayed as the title of the messagebox. This
            option is ignored on Mac OS X, where platform guidelines
            forbid the use of a title on this kind of dialog.

        alert (bool):
            Specified whether to ring the display bell.

        parent (Union[Window, Toplevel]):
            Makes the window the logical parent of the message box. The
            message box is displayed on top of its parent window.

        **kwargs (Dict):
            Optional keyword arguments.

    Returns:

        Union[str, None]:
            The symbolic name of the button pressed, or None if the
            window is closed without pressing a button.
    """
    dialog = MessageDialog(
        title=title,
        message=message,
        parent=parent,
        alert=alert,
        buttons=["Cancel", "No", "Yes:primary"],
        localize=True,
        **kwargs,
    )
    if "position" in kwargs:
        position = kwargs.pop("position")
    else:
        position = None
    dialog.show(position)
    return dialog.result