跳转至

DateEntry

ttkbootstrap.widgets.DateEntry (Frame)

A date entry widget combines the Combobox and a Button with a callback attached to the get_date function.

When pressed, a date chooser popup is displayed. The returned value is inserted into the combobox.

The date chooser popup will use the date in the combobox as the date of focus if it is in the format specified by the dateformat parameter. By default, this format is "%Y-%m-%d".

The bootstyle api may be used to change the style of the widget. The available colors include -> primary, secondary, success, info, warning, danger, light, dark.

The starting weekday on the date chooser popup can be changed with the firstweekday parameter. By default this value is 6, which represents "Sunday".

The Entry and Button widgets are accessible from the DateEntry.Entry and DateEntry.Button properties.

__init__(self, master=None, dateformat='%x', firstweekday=6, startdate=None, bootstyle='', **kwargs) special

Parameters:

Name Type Description Default
master Widget

The parent widget.

None
dateformat str

The format string used to render the text in the entry widget. For more information on acceptable formats, see https://strftime.org/

'%x'
firstweekday int

Specifies the first day of the week. 0=Monday, 1=Tuesday, etc...

6
startdate datetime

The date that is in focus when the widget is displayed. Default is current date.

None
bootstyle str

A style keyword used to set the focus color of the entry and the background color of the date button. Available options include -> primary, secondary, success, info, warning, danger, dark, light.

''
**kwargs Dict[str, Any]

Other keyword arguments passed to the frame containing the entry and date button.

{}
Source code in ttkbootstrap/widgets.py
def __init__(
    self,
    master=None,
    dateformat=r"%x",
    firstweekday=6,
    startdate=None,
    bootstyle="",
    **kwargs,
):
    """
    Parameters:

        master (Widget, optional):
            The parent widget.

        dateformat (str, optional):
            The format string used to render the text in the entry
            widget. For more information on acceptable formats, see https://strftime.org/

        firstweekday (int, optional):
            Specifies the first day of the week. 0=Monday, 1=Tuesday,
            etc...

        startdate (datetime, optional):
            The date that is in focus when the widget is displayed. Default is
            current date.

        bootstyle (str, optional):
            A style keyword used to set the focus color of the entry
            and the background color of the date button. Available
            options include -> primary, secondary, success, info,
            warning, danger, dark, light.

        **kwargs (Dict[str, Any], optional):
            Other keyword arguments passed to the frame containing the
            entry and date button.
    """
    self._dateformat = dateformat
    self._firstweekday = firstweekday

    self._startdate = startdate or datetime.today()
    self._bootstyle = bootstyle
    super().__init__(master, **kwargs)

    # add visual components
    entry_kwargs = {"bootstyle": self._bootstyle}
    if "width" in kwargs:
        entry_kwargs["width"] = kwargs.pop("width")

    self.entry = ttk.Entry(self, **entry_kwargs)
    self.entry.pack(side=tk.LEFT, fill=tk.X, expand=tk.YES)

    self.button = ttk.Button(
        master=self,
        command=self._on_date_ask,
        bootstyle=f"{self._bootstyle}-date",
    )
    self.button.pack(side=tk.LEFT)

    # starting value
    self.entry.insert(tk.END, self._startdate.strftime(self._dateformat))

configure(self, cnf=None, **kwargs)

Configure the options for this widget.

Parameters:

Name Type Description Default
cnf Dict[str, Any]

A dictionary of configuration options.

None
**kwargs

Optional keyword arguments.

{}
Source code in ttkbootstrap/widgets.py
def configure(self, cnf=None, **kwargs):
    """Configure the options for this widget.

    Parameters:

        cnf (Dict[str, Any], optional):
            A dictionary of configuration options.

        **kwargs:
            Optional keyword arguments.
    """
    if cnf is not None:
        return self._configure_get(cnf)
    else:
        return self._configure_set(**kwargs)