跳转至

Querybox

ttkbootstrap.dialogs.dialogs.Querybox

This class contains various static methods that request data from the end user.

get_color(parent=None, title='Color Chooser', initialcolor=None, **kwargs) staticmethod

Show a color picker and return the select color when the user pressed OK.

Parameters:

Name Type Description Default
parent Widget

The parent widget.

None
title str

Optional text that appears on the titlebar.

'Color Chooser'
initialcolor str

The initial color to display in the 'Current' color frame.

None

Returns:

Type Description
Tuple[rgb, hsl, hex]

The selected color in various colors models.

Source code in ttkbootstrap/dialogs/dialogs.py
@staticmethod
def get_color(
    parent=None, title="Color Chooser", initialcolor=None, **kwargs
):
    """Show a color picker and return the select color when the
    user pressed OK.

    ![](../../assets/dialogs/querybox-get-color.png)

    Parameters:

        parent (Widget):
            The parent widget.

        title (str):
            Optional text that appears on the titlebar.

        initialcolor (str):
            The initial color to display in the 'Current' color
            frame.

    Returns:

        Tuple[rgb, hsl, hex]:
            The selected color in various colors models.
    """
    from ttkbootstrap.dialogs.colorchooser import ColorChooserDialog

    dialog = ColorChooserDialog(parent, title, initialcolor)
    if "position" in kwargs:
        position = kwargs.pop("position")
    else:
        position = None
    dialog.show(position)
    return dialog.result

get_date(parent=None, title=' ', firstweekday=6, startdate=None, bootstyle='primary') staticmethod

Shows a calendar popup and returns the selection.

Parameters:

Name Type Description Default
parent Widget

The parent widget; the popup will appear to the bottom-right of the parent widget. If no parent is provided, the widget is centered on the screen.

None
title str

The text that appears on the popup titlebar.

' '
firstweekday int

Specifies the first day of the week. 0 is Monday, 6 is Sunday (the default).

6
startdate datetime

The date to be in focus when the widget is displayed;

None
bootstyle str

The following colors can be used to change the color of the title and hover / pressed color -> primary, secondary, info, warning, success, danger, light, dark.

'primary'

Returns:

Type Description
datetime

The date selected; the current date if no date is selected.

Source code in ttkbootstrap/dialogs/dialogs.py
@staticmethod
def get_date(
    parent=None,
    title=" ",
    firstweekday=6,
    startdate=None,
    bootstyle="primary",
):
    """Shows a calendar popup and returns the selection.

    ![](../../assets/dialogs/querybox-get-date.png)

    Parameters:

        parent (Widget):
            The parent widget; the popup will appear to the
            bottom-right of the parent widget. If no parent is
            provided, the widget is centered on the screen.

        title (str):
            The text that appears on the popup titlebar.

        firstweekday (int):
            Specifies the first day of the week. `0` is Monday, `6` is
            Sunday (the default).

        startdate (datetime):
            The date to be in focus when the widget is displayed;

        bootstyle (str):
            The following colors can be used to change the color of the
            title and hover / pressed color -> primary, secondary, info,
            warning, success, danger, light, dark.

    Returns:

        datetime:
            The date selected; the current date if no date is selected.
    """
    chooser = DatePickerDialog(
        parent=parent,
        title=title,
        firstweekday=firstweekday,
        startdate=startdate,
        bootstyle=bootstyle,
    )
    return chooser.date_selected

get_float(prompt='', title=' ', initialvalue=None, minvalue=None, maxvalue=None, parent=None, **kwargs) staticmethod

Request a float type input from the user.

Parameters:

Name Type Description Default
prompt str

A message to display in the message box above the entry widget.

''
title str

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

' '
initialvalue float

The initial value in the entry widget.

None
minvalue float

The minimum allowed value.

None
maxvalue float

The maximum allowed value.

None
parent Widget

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

None
**kwargs Dict

Other optional keyword arguments.

{}

Returns:

Type Description
float

The float value of the entry widget.

Source code in ttkbootstrap/dialogs/dialogs.py
@staticmethod
def get_float(
    prompt="",
    title=" ",
    initialvalue=None,
    minvalue=None,
    maxvalue=None,
    parent=None,
    **kwargs,
):
    """Request a float type input from the user.

    ![](../../assets/dialogs/querybox-get-float.png)

    Parameters:

        prompt (str):
            A message to display in the message box above the entry
            widget.

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

        initialvalue (float):
            The initial value in the entry widget.

        minvalue (float):
            The minimum allowed value.

        maxvalue (float):
            The maximum allowed value.

        parent (Widget):
            Makes the window the logical parent of the message box. The
            messagebox is displayed on top of its parent window.

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

    Returns:

        float:
            The float value of the entry widget.
    """
    initialvalue = initialvalue or ""
    if "position" in kwargs:
        position = kwargs.pop("position")
    else:
        position = None
    dialog = QueryDialog(
        prompt,
        title,
        initialvalue,
        minvalue,
        maxvalue,
        datatype=float,
        parent=parent,
        **kwargs,
    )
    dialog.show(position)
    return dialog._result

get_font(parent=None, **kwargs) staticmethod

Request a customized font

Parameters:

Name Type Description Default
parent Widget

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

None
**kwargs Dict

Other keyword arguments.

{}

Returns:

Type Description
Font

A font object.

Source code in ttkbootstrap/dialogs/dialogs.py
@staticmethod
def get_font(parent=None, **kwargs):
    """Request a customized font

    ![](../../assets/dialogs/querybox-get-font.png)

    Parameters:

        parent (Widget):
            Makes the window the logical parent of the dialog box. The
            dialog is displayed on top of its parent window.

        **kwargs (Dict):
            Other keyword arguments.

    Returns:

        Font:
            A font object.
    """
    if "position" in kwargs:
        position = kwargs.pop("position")
    else:
        position = None
    dialog = FontDialog(parent=parent, **kwargs)
    dialog.show(position)
    return dialog.result

get_integer(prompt='', title=' ', initialvalue=None, minvalue=None, maxvalue=None, parent=None, **kwargs) staticmethod

Request an integer type input from the user.

Parameters:

Name Type Description Default
prompt str

A message to display in the message box above the entry widget.

''
title str

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

' '
initialvalue int

The initial value in the entry widget.

None
minvalue int

The minimum allowed value.

None
maxvalue int

The maximum allowed value.

None
parent Widget

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

None
**kwargs Dict

Other optional keyword arguments.

{}

Returns:

Type Description
int

The integer value of the entry widget.

Source code in ttkbootstrap/dialogs/dialogs.py
@staticmethod
def get_integer(
    prompt="",
    title=" ",
    initialvalue=None,
    minvalue=None,
    maxvalue=None,
    parent=None,
    **kwargs,
):
    """Request an integer type input from the user.

    ![](../../assets/dialogs/querybox-get-integer.png)

    Parameters:

        prompt (str):
            A message to display in the message box above the entry
            widget.

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

        initialvalue (int):
            The initial value in the entry widget.

        minvalue (int):
            The minimum allowed value.

        maxvalue (int):
            The maximum allowed value.

        parent (Widget):
            Makes the window the logical parent of the message box. The
            messagebox is displayed on top of its parent window.

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

    Returns:

        int:
            The integer value of the entry widget.
    """
    initialvalue = initialvalue or ""
    if "position" in kwargs:
        position = kwargs.pop("position")
    else:
        position = None
    dialog = QueryDialog(
        prompt,
        title,
        initialvalue,
        minvalue,
        maxvalue,
        datatype=int,
        parent=parent,
        **kwargs,
    )
    dialog.show(position)
    return dialog._result

get_string(prompt='', title=' ', initialvalue=None, parent=None, **kwargs) staticmethod

Request a string type input from the user.

Parameters:

Name Type Description Default
prompt str

A message to display in the message box above the entry widget.

''
title str

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

' '
initialvalue Any

The initial value in the entry widget.

None
parent Widget

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

None
**kwargs Dict

Other optional keyword arguments.

{}

Returns:

Type Description
str

The string value of the entry widget.

Source code in ttkbootstrap/dialogs/dialogs.py
@staticmethod
def get_string(
    prompt="", title=" ", initialvalue=None, parent=None, **kwargs
):
    """Request a string type input from the user.

    ![](../../assets/dialogs/querybox-get-string.png)

    Parameters:

        prompt (str):
            A message to display in the message box above the entry
            widget.

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

        initialvalue (Any):
            The initial value in the entry widget.

        parent (Widget):
            Makes the window the logical parent of the message box. The
            messagebox is displayed on top of its parent window.

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

    Returns:

        str:
            The string value of the entry widget.
    """
    initialvalue = initialvalue or ""
    if "position" in kwargs:
        position = kwargs.pop("position")
    else:
        position = None
    dialog = QueryDialog(
        prompt, title, initialvalue, parent=parent, **kwargs
    )
    dialog.show(position)
    return dialog._result