pyglet.window.dialog

Classes

class FileOpenDialog

Bases: EventDispatcher

Opens a system file dialog window for opening files.

Added in version 3.0.

Methods

open() None

Open a file dialog window to select files according to the configuration.

Return type:

None

Events

on_dialog_open(filenames: list[str]) Literal[True] | None

Event for filename choice.

Parameters:

filenames (list[str]) – The selected filename paths chosen by the user. May be empty if nothing is chosen.

Return type:

Literal[True] | None

__init__(
title: str = 'Open File',
initial_dir: str | Path | None = None,
initial_file: str | None = None,
filetypes: list[tuple[str, str]] | None = None,
multiple: bool = False,
) None

Establish how the open file dialog will behave.

Parameters:
  • title (str) – The Dialog Window name. Defaults to “Open File”.

  • initial_dir (str | Path | None) – The directory to start in. If a path is not given, it is up the OS to determine behavior. On Windows, if None is passed, it will open to the last used directory.

  • initial_file (str | None) – The filename to prepopulate with when opening. Not supported on Mac OS.

  • filetypes (list[tuple[str, str]] | None) – An optional list of tuples containing (name, extension) to filter by. If none are given, all files will be shown and selectable. For example: [(“PNG”, “.png”), (“24-bit Bitmap”, “.bmp”)] For multiple file types in the same selection, separate by a semicolon. For example: [(“Images”, “.png;.bmp”)]`

  • multiple (bool) – bool True if multiple files can be selected. Defaults to False.

classmethod __new__(*args, **kwargs)
class FileSaveDialog

Bases: EventDispatcher

Opens a system file dialog window for saving files.

Added in version 3.0.

Methods

open() None

Open the file dialog window to save files according to the configuration.

Return type:

None

Events

on_dialog_save(filename: str) Literal[True] | None

Event for filename choice.

Parameters:

filename (str) – The resulting filename a user input. The string may be empty if user input nothing or cancelled the operation.

Return type:

Literal[True] | None

__init__(
title: str = 'Save As',
initial_dir: str | Path | None = None,
initial_file: str | None = None,
filetypes: list[tuple[str, str]] | None = None,
default_ext: str = '',
) None

Establish how the save file dialog will behave.

Parameters:
  • title (str) – The Dialog Window name. Defaults to “Save As”.

  • initial_dir (str | Path | None) – The directory to start in. If a path is not given, it is up the OS to determine behavior. On Windows, if None is passed, it will open to the last used directory.

  • initial_file (str | None) – A default file name to be filled in. Defaults to None.

  • filetypes (list[tuple[str, str]] | None) – An optional list of tuples containing (name, extension) to filter to. If the default_ext argument is not given, this list also dictates the extension that will be added to the entered file name. If a list of filetypes are not give, you can enter any file name to save as. For example: [(“PNG”, “.png”), (“24-bit Bitmap”, “.bmp”)]

  • default_ext (str) – A default file extension to add to the file. This will override the filetypes list if given, but will not override a manually entered extension.

classmethod __new__(*args, **kwargs)