Querybox#

Querybox prompts the user for a value and returns it. Every method is a static method — call it on the class (Querybox.get_string("Name?")). Each blocks until the user responds and returns the entered or chosen value, or None if the dialog is cancelled.

Two options are common to every method: parent (the window to center over and block; defaults to the application root) and the keyword-only position (an (x, y) top-left screen position, centered on parent by default).

Text and number input#

static get_string(prompt='', title=' ', initialvalue=None, parent=None, *, position=None)

Ask for a line of text.

Parameters:
  • prompt – the label shown above the entry.

  • initialvalue – the value the entry starts with.

Returns:

the entered string, or None if cancelled.

static get_integer(prompt='', title=' ', initialvalue=None, minvalue=None, maxvalue=None, parent=None, *, position=None)

Ask for a whole number, rejecting non-integer or out-of-range input.

Parameters:
  • minvalue – the smallest value accepted.

  • maxvalue – the largest value accepted.

Returns:

the entered int, or None if cancelled.

static get_float(prompt='', title=' ', initialvalue=None, minvalue=None, maxvalue=None, parent=None, *, position=None)

Ask for a decimal number, rejecting non-numeric or out-of-range input.

Parameters:
  • minvalue – the smallest value accepted.

  • maxvalue – the largest value accepted.

Returns:

the entered float, or None if cancelled.

static get_item(prompt='', title=' ', initialvalue=None, items=None, parent=None, *, position=None)

Ask the user to choose one value from a list.

Parameters:
  • items – the list of values to choose from.

  • initialvalue – the value selected initially.

Returns:

the chosen item, or None if cancelled.

Pickers#

static get_date(parent=None, title=' ', first_weekday=6, start_date=None, bootstyle='primary', *, show_outside_days=True, position=None)

Open a calendar popup to pick a date (see DatePickerDialog).

Parameters:
  • first_weekday – the leftmost weekday column, 0 (Monday)–6 (Sunday).

  • start_date – the date shown selected initially; defaults to today.

  • bootstyle – the calendar’s accent color.

  • show_outside_days – show days spilling in from the adjacent months.

Returns:

the chosen datetime.date, or None if cancelled.

static get_color(parent=None, title='Color Chooser', initialcolor=None, *, position=None)

Open the color chooser (see ColorChooserDialog).

Parameters:

initialcolor – the color selected initially (a hex string).

Returns:

the chosen color, or None if cancelled.

static get_font(parent=None, *, position=None)

Open the font selector (see FontDialog).

Returns:

the chosen Font, or None if cancelled.

Files#

These wrap tkinter.filedialog; extra keyword arguments (initialdir, filetypes, defaultextension, …) pass straight through. A cancelled dialog returns None.

static get_open_filename(parent=None, **kwargs)

Choose one existing file to open.

Returns:

the file path, or None if cancelled.

static get_open_filenames(parent=None, **kwargs)

Choose one or more existing files to open.

Returns:

a tuple of file paths, or None if cancelled.

static get_save_filename(parent=None, **kwargs)

Choose a file path to save to (prompting to confirm an overwrite).

Returns:

the file path, or None if cancelled.

static get_directory(parent=None, **kwargs)

Choose a directory.

Returns:

the directory path, or None if cancelled.

See also#

  • Dialogs — how to use them, with examples.

  • Messagebox — the message-dialog facade.

  • Pickers — the date, color, and font dialog classes these build.