TextInput¶
Bases:
pygame_menu.widgets.core.widget.Widget
Text input widget.
Parameters: - title (str) – Text input title
- textinput_id (str) – ID of the text input
- input_type (str) – Type of data
- input_underline (str) – Character drawn under the input
- cursor_color (tuple) – Color of cursor
- cursor_selection_color (tuple) – Selection box color
- cursor_selection_enable (bool) – Enables selection of text
- copy_paste_enable (bool) – Enables copy, paste and cut
- history (int) – Maximum number of editions stored
- maxchar (int) – Maximum length of input
- maxwidth (int) – Maximum size of the text to be displayed (overflow), if 0 this feature is disabled
- maxwidth_dynamically_update (bool) – Dynamically update maxwidth depending on char size
- onchange (callable, None) – Callback when changing the text input
- onreturn (callable, None) – Callback when pressing return on the text input
- password (bool) – Input string is displayed as a password
- password_char (str) – Character used by password type
- repeat_keys_initial_ms (int, float) – Time in ms before keys are repeated when held
- repeat_keys_interval_ms (int, float) – Interval between key press repetition when held
- repeat_mouse_interval_ms (int, float) – Interval between mouse events when held
- repeat_touch_interval_ms (int, float) – Interval between mouse events when held
- tab_size (int) – Tab whitespace characters
- text_ellipsis (str) – Ellipsis text when overflow occurs (input length exceeds maxwidth)
- valid_chars (list) – List of chars that are valid, None if all chars are valid
- kwargs (dict) – Optional keyword arguments
Run
on_return
callback when return event. A callback function receives the following arguments:callback_func(value, *args, *widget._args, **widget._kwargs)
- with:
value
(if something is returned byget_value()
)args
given to this methodargs
of the widgetkwargs
of the widget
Parameters: - args – Extra arguments passed to the callback
- args – any
Returns: None
Run
on_change
callback after change event is triggered. A callback function receives the following arguments:callback_func(value, *args, *widget._args, **widget._kwargs)
- with:
value
(if something is returned byget_value()
)args
given to this methodargs
of the widgetkwargs
of the widget
Parameters: - args – Extra arguments passed to the callback
- args – any
Returns: None
Change widget id.
Parameters: widget_id (str) – Widget ID Returns: None
Clear the current text.
Returns: None
Draw the widget shape.
Parameters: surface ( pygame.Surface
) – Surface to drawReturns: None
Draw selection effect on widget.
Parameters: surface ( pygame.Surface
) – Surface to drawReturns: None
Return the widget alignment.
Returns: Widget align, see locals Return type: str
Get attribute value.
Parameters: - key (str) – Key of the attribute
- default (any) – Value if does not exists
Returns: Attribute data
Return type: any
Return a dict with the information of the widget font.
Dict values:
antialias
Font antialias (bool)background_color
Background color (tuple)color
Font color (tuple)name
Name of the font (str)selected_color
Selected color (tuple)size
Size of the font (int)
Returns: Dict Return type: dict
Return the widget ID.
Returns: Widget ID Return type: str
Return the widget margin.
Returns: Widget margin (left, top) Return type: tuple
Return the menu reference (if exists).
Returns: Menu reference Return type: pygame_menu.Menu
, None
Return the widget padding.
Returns: Widget padding (top, right, bottom, left) Return type: tuple
Return the Rect object, this forces the widget rendering.
Returns: Widget rect Return type: pygame.Rect
Return time the widget has been selected in miliseconds. If the widget is not currently selected, return 0.
Returns: Time in ms Return type: float
Return the selection effect.
Returns: Selection effect Return type: pygame_menu.widgets.core.Selection
Return the widget title.
Returns: Widget title Return type: str
Return the value of the text.
Returns: Text inside the widget Return type: str
Hides widget.
Returns: None
Set the alignment of the widget.
Parameters: align (str) – Widget align, see locals Returns: None
Set widget attribute.
Parameters: - key (str) – Key of the attribute
- value (any) – Value of the attribute
Returns: None
Set widget background color.
Parameters: - color (tuple, list,
pygame_menu.baseimage.BaseImage
, None) – Widget background color - inflate (tuple, list) – Inflate background in x,y
Returns: None
- color (tuple, list,
Enable interfaces to control the widget.
Parameters: Returns: None
Set the text font.
Parameters: - font (str) – Font name (see
pygame.font.match_font
for precise format) - font_size (int) – Size of font in pixels
- color (tuple) – Text color
- selected_color (tuple) – Text color when widget is selected
- background_color (tuple) – Font background color
- antialias (bool) – Determines if antialias is applied to font (uses more processing power)
Returns: None
- font (str) – Font name (see
Set Widget margin (left, top).
Parameters: Returns: None
Set widget max width (column support) if
force_fit_text
is enabled.Parameters: width (int, float, None) – Width in px, None if max width is disabled Returns: None
Set the menu reference.
Parameters: menu ( pygame_menu.Menu
) – Menu objectReturns: None
Set the Widget padding according to CSS rules.
- If an integer or float is provided: top, right, bottom and left values will be the same
- If 2-item tuple is provided: top and bottom takes the first value, left and right the second
- If 3-item tuple is provided: top will take the first value, left and right the second, and bottom the third
- If 4-item tuple is provided: padding will be (top, right, bottom, left)
Note
See CSS W3Schools for more info about padding.
Parameters: padding (int, float, tuple, list) – Can be a single number, or a tuple of 2, 3 or 4 elements following CSS style Returns: None
Set the position.
Parameters: Returns: None
Mark the widget as selected.
Parameters: selected (bool) – Set item as selected Returns: None
Set the selection effect handler.
Parameters: selection ( pygame_menu.widgets.core.Selection
) – Selection effect classReturns: None
Show text shadow.
Parameters: Returns: None
Set sound engine to the widget.
Parameters: sound ( pygame_menu.sound.Sound
) – Sound objectReturns: None
Update the widget title.
Parameters: title (str) – New title Returns: None
Set widget visible.
Returns: None
Checks if the widget width/height has changed because events. If so, return true and set the status of the widget (menu widget position needs update) as false. This method is used by
.update()
from Menu class.Returns: True if the widget position has changed by events after the rendering. Return type: bool
Update internal variable according to the given events list and fire the callbacks.
Parameters: events (list[ pygame.event.Event
]) – List of pygame eventsReturns: True if updated Return type: bool
Updates font. This method receives a style dict (non empty) containing the following keys:
antialias
Font antialias (bool)background_color
Background color (tuple)color
Font color (tuple)name
Name of the font (str)selected_color
Selected color (tuple)size
Size of the font (int)
Note
If a key is not defined it will be rewritten using current font style from
.get_font_info()
method.Parameters: style (dict) – Font style dict Returns: None