LineInputDialog

class pygamelib.gfx.ui.LineInputDialog(title=None, label='Input a value:', default='', filter=InputValidator.PRINTABLE_FILTER, config=None)

Bases: Dialog

The LineInputDialog allows the user to enter and edit a single line of text.

This dialog can be configured to accept either anything printable or only digits.

The show() method returns the user input.

Key mapping:

  • ESC: set the user input to “” and exit from the show() method.

  • ENTER: Exit from the show() method. Returns the user input.

  • BACKSPACE / DELETE: delete a character (both keys have the same result)

  • All other keys input characters in the input field.

In all cases, when the dialog is closed, the user input is returned.

Like all dialogs, it is automatically destroyed on exit of the show() method. It is also deleted from the screen buffer.

__init__(title=None, label='Input a value:', default='', filter=InputValidator.PRINTABLE_FILTER, config=None) None
Parameters:
  • title (str) – The short title of the dialog. Only used when the dialog is not borderless.

  • label (str | base.Text) – The label of the dialog (usually a one line instruction).

  • default (str) – The default value in the input field.

  • filter (InputValidator) – Sets the type of accepted input. It comes from the constants module.

  • config (UiConfig) – The configuration object.

Example:

line_input = LineInputDialog(
    "Name the pet",
    "Enter the name of your pet:",
    "Stupido",
)
screen.place(line_input, 10, 10)
pet_name = line_input.show()

Methods

__init__([title, label, default, filter, config])

param title:

The short title of the dialog. Only used when the dialog is not

render_to_buffer(buffer, row, column, ...)

Render the object from the display buffer to the frame buffer.

show()

Show the dialog and execute the event loop.

Attributes

config

Get and set the config object (UiConfig).

label

Get and set the label of the dialog, it has to be a str or base.Text.

title

Get and set the title of the dialog, it has to be a str.

user_input

Facility to store and retrieve the user input.

property config

Get and set the config object (UiConfig).

property label: Text

Get and set the label of the dialog, it has to be a str or base.Text.

render_to_buffer(buffer, row, column, buffer_height, buffer_width) None

Render the object from the display buffer to the frame buffer.

This method is automatically called by pygamelib.engine.Screen.render().

Parameters:
  • buffer (numpy.array) – A screen buffer to render the item into.

  • row (int) – The row to render in.

  • column (int) – The column to render in.

  • height (int) – The total height of the display buffer.

  • width (int) – The total width of the display buffer.

show()

Show the dialog and execute the event loop. Until this method returns, all keyboards event are processed by the local event loop. This is also true if called from the main event loop.

This event loop returns the either “” or what is displayed in the input field.

Example:

value = line_input.show()
property title: str

Get and set the title of the dialog, it has to be a str.

property user_input

Facility to store and retrieve the user input.