Pickers#

These are the dialog classes behind Querybox.get_date(), Querybox.get_color(), and Querybox.get_font(). Querybox constructs them for you and hands back the result, but you can construct any of them directly when you want more control over placement, styling, or lifecycle.

DatePickerDialog#

A calendar popup for choosing a date. It opens near the parent widget, lets the user page through months, and returns the selected day.

Options#

Set these on the constructor — DatePickerDialog(parent=None, title=" ", first_weekday=6, start_date=None, bootstyle="primary", autoshow=True, show_outside_days=True).

Option

Type

Description

parent

Widget

The window to position near and block. Defaults to the application root.

title

str

The text shown on the window’s title bar.

first_weekday

int

The leftmost weekday column, 0 (Monday)–6 (Sunday). Default 6.

start_date

date

The date shown selected initially. Defaults to today.

bootstyle

str

The calendar’s accent color. Default "primary".

autoshow

bool

Display immediately on construction. Default True; pass False to call show() yourself.

show_outside_days

bool

Show days spilling in from the adjacent months. Default True.

Methods#

show(position=None, wait_for_result=True)

Display the dialog. Blocks until the user picks a date or cancels, then stores the outcome on result.

Parameters:
  • position – An (x, y) top-left screen position. Positioned near parent by default.

  • wait_for_result – Block until the dialog closes. Default True.

Returns:

None — read result after it returns.

result

The chosen datetime.date, or None if cancelled.

FontDialog#

A font selector for choosing a family, size, weight, slant, and effects, with a live preview of the current selection. A Dialog subclass, so it also carries the base Dialog interface (close(), the create_* build hooks, …).

Options#

Set these on the constructor — FontDialog(title="Font Selector", parent=None, default_font="TkDefaultFont").

Option

Type

Description

title

str

The text shown on the window’s title bar. Default "Font Selector".

parent

Widget

The window to center over and block. Defaults to the application root.

default_font

str

The named font shown selected initially. Default "TkDefaultFont".

Methods#

show(position=None, wait_for_result=True)

Display the dialog. Blocks until the user picks a font or cancels, then stores the outcome on result.

Parameters:
  • position – An (x, y) top-left screen position. Centered on parent by default.

  • wait_for_result – Block until the dialog closes. Default True.

Returns:

None — read result after it returns.

result

The chosen Font, or None if cancelled.

ColorChooserDialog#

A color picker with color-model sliders and a preview. The user can adjust the sliders, enter a value, or reach the eyedropper (ColorDropperDialog) to sample a color from the screen. A Dialog subclass, so it also carries the base Dialog interface (close(), the create_* build hooks, …).

Options#

Set these on the constructor — ColorChooserDialog(parent=None, title="Color Chooser", initialcolor=None).

Option

Type

Description

parent

Widget

The window to center over and block. Defaults to the application root.

title

str

The text shown on the window’s title bar. Default "Color Chooser".

initialcolor

str

The color selected initially, a hex string like "#2b8cee".

Methods#

show(position=None, wait_for_result=True)

Display the dialog. Blocks until the user picks a color or cancels, then stores the outcome on result.

Parameters:
  • position – An (x, y) top-left screen position. Centered on parent by default.

  • wait_for_result – Block until the dialog closes. Default True.

Returns:

None — read result after it returns.

result

The chosen color, or None if cancelled.

ColorDropperDialog#

An eyedropper that picks the color of any pixel on screen — the same dropper reachable from ColorChooserDialog. It takes over the screen so the next click samples the color under the cursor.

Methods#

The constructor takes no arguments — ColorDropperDialog().

show()

Take over the screen; the next click picks the color under the cursor. A right-click or Escape cancels. The outcome is stored on result.

Returns:

None — read result after it returns.

result

The picked color, or None if cancelled.

See also#

  • Querybox — the input-and-picker facade.

  • Dialogs — how to use them, with examples.