WidgetManager¶
- class pygame_menu._widgetmanager.WidgetManager(menu)[source]
Add/Remove widgets to the Menu.
- Parameters
menu (
Menu
) – Menu reference
- button(title, action=None, *args, **kwargs)[source]
Adds a button to the Menu.
The arguments and unknown keyword arguments are passed to the action, if it’s a callable object:
action(*args)
If
accept_kwargs=True
then the**kwargs
are also unpacked on action call:action(*args, **kwargs)
If
onselect
is defined, the callback is executed as follows, whereselected
is a boolean representing the selected status:onselect(selected, widget, menu)
- kwargs (Optional)
accept_kwargs
(bool) – Button action accepts**kwargs
if it’s a callable object (function-type),False
by defaultalign
(str) – Widget alignmentback_count
(int) – Number of menus to go back if action ispygame_menu.events.BACK
event, default is1
background_color
(tuple, list, str, int,pygame.Color
,pygame_menu.baseimage.BaseImage
) – Color of the background.None
for no-colorbackground_inflate
(tuple, list) – Inflate background on x-axis and y-axis (x, y) in pxborder_color
(tuple, list, str, int,pygame.Color
) – Widget border color.None
for no-colorborder_inflate
(tuple, list) – Widget border inflate on x-axis and y-axis (x, y) in pxborder_position
(str, tuple, list) – Widget border positioning. It can be a single position, or a tuple/list of positions. Only are accepted: north, south, east, and west. Seepygame_menu.locals
border_width
(int) – Border width in px. If0
disables the borderbutton_id
(str) – Widget IDcursor
(int,pygame.cursors.Cursor
, None) – Cursor of the widget if the mouse is placed overfont_background_color
(tuple, list, str, int,pygame.Color
, None) – Widget font background colorfont_color
(tuple, list, str, int,pygame.Color
) – Widget font colorfont_name
(str,pathlib.Path
,pygame.font.Font
) – Widget font pathfont_shadow_color
(tuple, list, str, int,pygame.Color
) – Font shadow colorfont_shadow_offset
(int) – Font shadow offset in pxfont_shadow_position
(str) – Font shadow position, see locals for positionfont_shadow
(bool) – Font shadow is enabled or disabledfont_size
(int) – Font size of the widgetmargin
(tuple, list) – Widget (left, bottom) margin in pxonselect
(callable, None) – Callback executed when selecting the widgetpadding
(int, float, tuple, list) – Widget padding according to CSS rules. General shape: (top, right, bottom, left)readonly_color
(tuple, list, str, int,pygame.Color
) – Color of the widget if readonly modereadonly_selected_color
(tuple, list, str, int,pygame.Color
) – Color of the widget if readonly mode and is selectedselection_color
(tuple, list, str, int,pygame.Color
) – Color of the selected widget; only affects the font colorselection_effect
(pygame_menu.widgets.core.Selection
) – Widget selection effecttab_size
(int) – Width of a tab characterunderline_color
(tuple, list, str, int,pygame.Color
, None) – Color of the underline. IfNone
use the same color of the textunderline_offset
(int) – Vertical offset in px.2
by defaultunderline_width
(int) – Underline width in px.2
by defaultunderline
(bool) – Enables text underline, using a properly placed decoration.False
by default
Note
All theme-related optional kwargs use the default Menu theme if not defined.
Note
Using
action=None
is the same as usingaction=pygame_menu.events.NONE
.Note
This is applied only to the base Menu (not the currently displayed, stored in
_current
pointer); for such behaviour apply topygame_menu.menu.Menu.get_current()
object.Warning
Be careful with kwargs collision. Consider that all optional documented kwargs keys are removed from the object.
- Parameters
- Returns
Widget object
- Return type
- clock(clock_format='%Y/%m/%d %H:%M:%S', clock_id='', onselect=None, selectable=False, title_format='{0}', **kwargs)[source]
Add a clock label to the Menu. This creates a Label with a text generator that request a string from
time.strftime
module usingclock_format
.- Commonly used format codes:
%Y – Year with century as a decimal number
%m – Month as a decimal number [01, 12]
%d – Day of the month as a decimal number [01, 31]
%H – Hour (24-hour clock) as a decimal number [00, 23]
%M – Minute as a decimal number [00, 59]
%S – Second as a decimal number [00, 61]
%z – Time zone offset from UTC
%a – Locale’s abbreviated weekday name
%A – Locale’s full weekday name
%b – Locale’s abbreviated month name
%B – Locale’s full month name
%c – Locale’s appropriate date and time representation
%I – Hour (12-hour clock) as a decimal number [01, 12]
%p – Locale’s equivalent of either AM or PM
If
onselect
is defined, the callback is executed as follows, whereselected
is a boolean representing the selected status:onselect(selected, widget, menu)
- kwargs (Optional)
align
(str) – Widget alignmentbackground_color
(tuple, list, str, int,pygame.Color
,pygame_menu.baseimage.BaseImage
) – Color of the background.None
for no-colorbackground_inflate
(tuple, list) – Inflate background on x-axis and y-axis (x, y) in pxborder_color
(tuple, list, str, int,pygame.Color
) – Widget border color.None
for no-colorborder_inflate
(tuple, list) – Widget border inflate on x-axis and y-axis (x, y) in pxborder_position
(str, tuple, list) – Widget border positioning. It can be a single position, or a tuple/list of positions. Only are accepted: north, south, east, and west. Seepygame_menu.locals
border_width
(int) – Border width in px. If0
disables the bordercursor
(int,pygame.cursors.Cursor
, None) – Cursor of the widget if the mouse is placed overfont_background_color
(tuple, list, str, int,pygame.Color
, None) – Widget font background colorfont_color
(tuple, list, str, int,pygame.Color
) – Widget font colorfont_name
(str,pathlib.Path
,pygame.font.Font
) – Widget font pathfont_shadow_color
(tuple, list, str, int,pygame.Color
) – Font shadow colorfont_shadow_offset
(int) – Font shadow offset in pxfont_shadow_position
(str) – Font shadow position, see locals for positionfont_shadow
(bool) – Font shadow is enabled or disabledfont_size
(int) – Font size of the widgetmargin
(tuple, list) – Widget (left, bottom) margin in pxpadding
(int, float, tuple, list) – Widget padding according to CSS rules. General shape: (top, right, bottom, left)selection_color
(tuple, list, str, int,pygame.Color
) – Color of the selected widget; only affects the font colorselection_effect
(pygame_menu.widgets.core.Selection
) – Widget selection effect. Applied only ifselectable
isTrue
tab_size
(int) – Width of a tab characterunderline_color
(tuple, list, str, int,pygame.Color
, None) – Color of the underline. IfNone
use the same color of the textunderline_offset
(int) – Vertical offset in px.2
by defaultunderline_width
(int) – Underline width in px.2
by defaultunderline
(bool) – Enables text underline, using a properly placed decoration.False
by default
Note
All theme-related optional kwargs use the default Menu theme if not defined.
Note
This is applied only to the base Menu (not the currently displayed, stored in
_current
pointer); for such behaviour apply topygame_menu.menu.Menu.get_current()
object.- Parameters
clock_format (
str
) – Format of clock used bytime.strftime
clock_id (
str
) – ID of the clockonselect (
Optional
[Callable
[[bool
,Widget
,Menu
],Any
]]) – Callback executed when selecting the widget; only executed ifselectable
isTrue
selectable (
bool
) – Label accepts user selection; useful to move along the Menu using label selectiontitle_format (
str
) – Title format which accepts{0}
as the string fromtime.strftime
, for example,'My Clock {0}'
can be a title formatkwargs – Optional keyword arguments
- Returns
Widget object
- Return type
- color_input(title, color_type, color_id='', default='', hex_format='none', input_separator=',', input_underline='_', onchange=None, onreturn=None, onselect=None, **kwargs)[source]
Add a color widget with RGB or HEX format to the Menu. Includes a preview box that renders the given color.
The callbacks (if defined) receive the current value and all unknown keyword arguments, where
current_color=widget.get_value()
:onchange(current_color, **kwargs) onreturn(current_color, **kwargs)
If
onselect
is defined, the callback is executed as follows, whereselected
is a boolean representing the selected status:onselect(selected, widget, menu)
- kwargs (Optional)
align
(str) – Widget alignmentbackground_color
(tuple, list, str, int,pygame.Color
,pygame_menu.baseimage.BaseImage
) – Color of the background.None
for no-colorbackground_inflate
(tuple, list) – Inflate background on x-axis and y-axis (x, y) in pxborder_color
(tuple, list, str, int,pygame.Color
) – Widget border color.None
for no-colorborder_inflate
(tuple, list) – Widget border inflate on x-axis and y-axis (x, y) in pxborder_position
(str, tuple, list) – Widget border positioning. It can be a single position, or a tuple/list of positions. Only are accepted: north, south, east, and west. Seepygame_menu.locals
border_width
(int) – Border width in px. If0
disables the bordercursor
(int,pygame.cursors.Cursor
, None) – Cursor of the widget if the mouse is placed overdynamic_width
(bool) – IfTrue
the widget width changes if the pre-visualization color box is active or notfont_background_color
(tuple, list, str, int,pygame.Color
, None) – Widget font background colorfont_color
(tuple, list, str, int,pygame.Color
) – Widget font colorfont_name
(str,pathlib.Path
,pygame.font.Font
) – Widget font pathfont_shadow_color
(tuple, list, str, int,pygame.Color
) – Font shadow colorfont_shadow_offset
(int) – Font shadow offset in pxfont_shadow_position
(str) – Font shadow position, see locals for positionfont_shadow
(bool) – Font shadow is enabled or disabledfont_size
(int) – Font size of the widgetinput_underline_vmargin
(int) – Vertical margin of underline in pxmargin
(tuple, list) – Widget (left, bottom) margin in pxmaxwidth_dynamically_update
(bool) - Dynamically update maxwidth depending on char size.True
by defaultpadding
(int, float, tuple, list) – Widget padding according to CSS rules. General shape: (top, right, bottom, left)previsualization_margin
(int) – Pre-visualization left margin from text input in px. Default is0
previsualization_width
(int, float) – Pre-visualization width as a factor of the height. Default is3
readonly_color
(tuple, list, str, int,pygame.Color
) – Color of the widget if readonly modereadonly_selected_color
(tuple, list, str, int,pygame.Color
) – Color of the widget if readonly mode and is selectedrepeat_keys_initial_ms
(int, float) - Time in ms before keys are repeated when held in ms.400
by defaultrepeat_keys_interval_ms
(int, float) - Interval between key press repetition when held in ms.50
by defaultrepeat_mouse_interval_ms
(int, float) - Interval between mouse events when held in ms.400
by defaultselection_color
(tuple, list, str, int,pygame.Color
) – Color of the selected widget; only affects the font colorselection_effect
(pygame_menu.widgets.core.Selection
) – Widget selection effecttab_size
(int) – Width of a tab character
Note
All theme-related optional kwargs use the default Menu theme if not defined.
Note
This is applied only to the base Menu (not the currently displayed, stored in
_current
pointer); for such behaviour apply topygame_menu.menu.Menu.get_current()
object.Warning
Be careful with kwargs collision. Consider that all optional documented kwargs keys are removed from the object.
- Parameters
color_type (
Literal
[‘rgb’, ‘hex’]) – Type of the color inputcolor_id (
str
) – ID of the color inputdefault (
Union
[str
,Tuple
[int
,int
,int
]]) – Default value to display, if RGB type it must be a tuple(r, g, b)
, if HEX must be a string"#XXXXXX"
hex_format (
Literal
[‘lower’, ‘upper’, ‘none’]) – Hex format string modeinput_separator (
str
) – Divisor between RGB channels, not valid in HEX formatinput_underline (
str
) – Underline characteronchange (
Optional
[Callable
]) – Callback executed when changing the values of the color textonreturn (
Optional
[Callable
]) – Callback executed when pressing return on the color text inputonselect (
Optional
[Callable
[[bool
,Widget
,Menu
],Any
]]) – Callback executed when selecting the widgetkwargs – Optional keyword arguments
- Returns
Widget object
- Return type
- configure_defaults_widget(widget)[source]
Apply default menu settings to widget. This method does not add widget to the Menu.
- dropselect(title, items, default=- 1, dropselect_id='', onchange=None, onreturn=None, onselect=None, open_middle=False, placeholder='Select an option', placeholder_add_to_selection_box=True, **kwargs)[source]
Add a dropselect to the Menu: Drop select is a selector within a Frame. This drops a vertical frame if requested.
Drop select can contain selectable items (options), but only one can be selected.
The items of the DropSelect are:
items = [('Item1', a, b, c...), ('Item2', d, e, f...)]
The callbacks receive the current selected item, its index in the list, the associated arguments, and all unknown keyword arguments, where
selected_item=widget.get_value()
andselected_index=widget.get_index()
:onchange((selected_item, selected_index), a, b, c..., **kwargs) onreturn((selected_item, selected_index), a, b, c..., **kwargs)
For example, if
selected_index=0
thenselected_item=('Item1', a, b, c...)
.If
onselect
is defined, the callback is executed as follows, whereselected
is a boolean representing the selected status:onselect(selected, widget, menu)
- kwargs (Optional)
align
(str) – Widget alignmentbackground_color
(tuple, list, str, int,pygame.Color
,pygame_menu.baseimage.BaseImage
) – Color of the background.None
for no-colorbackground_inflate
(tuple, list) – Inflate background on x-axis and y-axis (x, y) in pxborder_color
(tuple, list, str, int,pygame.Color
) – Widget border color.None
for no-colorborder_inflate
(tuple, list) – Widget border inflate on x-axis and y-axis (x, y) in pxborder_position
(str, tuple, list) – Widget border positioning. It can be a single position, or a tuple/list of positions. Only are accepted: north, south, east, and west. Seepygame_menu.locals
border_width
(int) – Border width in px. If0
disables the bordercursor
(int,pygame.cursors.Cursor
, None) – Cursor of the widget if the mouse is placed overfont_background_color
(tuple, list, str, int,pygame.Color
, None) – Widget font background colorfont_color
(tuple, list, str, int,pygame.Color
) – Widget font colorfont_name
(str,pathlib.Path
,pygame.font.Font
) – Widget font pathfont_shadow_color
(tuple, list, str, int,pygame.Color
) – Font shadow colorfont_shadow_offset
(int) – Font shadow offset in pxfont_shadow_position
(str) – Font shadow position, see locals for positionfont_shadow
(bool) – Font shadow is enabled or disabledfont_size
(int) – Font size of the widgetmargin
(tuple, list) – Widget (left, bottom) margin in pxpadding
(int, float, tuple, list) – Widget padding according to CSS rules. General shape: (top, right, bottom, left)readonly_color
(tuple, list, str, int,pygame.Color
) – Color of the widget if readonly modereadonly_selected_color
(tuple, list, str, int,pygame.Color
) – Color of the widget if readonly mode and is selectedselection_color
(tuple, list, str, int,pygame.Color
) – Color of the selected widget; only affects the font colorselection_effect
(pygame_menu.widgets.core.Selection
) – Widget selection effecttab_size
(int) – Width of a tab character
- kwargs for modifying selection box/option style (Optional)
scrollbar_color
(tuple, list, str, int,pygame.Color
) – Scrollbar colorscrollbar_cursor
(int,pygame.cursors.Cursor
, None) – Cursor of the scrollbars if the mouse is placed overscrollbar_shadow_color
(tuple, list, str, int,pygame.Color
) – Color of the shadow of each scrollbarscrollbar_shadow_offset
(int) – Offset of the scrollbar shadow in pxscrollbar_shadow_position
(str) – Position of the scrollbar shadow. Seepygame_menu.locals
scrollbar_shadow
(bool) – Indicate if a shadow is drawn on each scrollbarscrollbar_slider_color
(tuple, list, str, int,pygame.Color
) – Color of the slidersscrollbar_slider_hover_color
(tuple, list, str, int,pygame.Color
) – Color of the slider if hovered or clickedscrollbar_slider_pad
(int, float) – Space between slider and scrollbars borders in pxscrollbar_thick
(int) – Scrollbar thickness in pxscrollbars
(str) – Scrollbar position. Seepygame_menu.locals
selection_box_arrow_color
(tuple, list, str, int,pygame.Color
) – Selection box arrow colorselection_box_arrow_margin
(tuple) – Selection box arrow margin (left, right, vertical) in pxselection_box_bgcolor
(tuple, list, str, int,pygame.Color
) – Selection box background colorselection_box_border_color
(tuple, list, str, int,pygame.Color
) – Selection box border colorselection_box_border_width
(int) – Selection box border widthselection_box_height
(int) – Selection box height, counted as how many options are packed before showing scrollselection_box_inflate
(tuple) – Selection box inflate on x-axis and y-axis (x, y) in pxselection_box_margin
(tuple, list) – Selection box on x-axis and y-axis (x, y) margin from title in pxselection_box_text_margin
(int) – Selection box text margin (left) in pxselection_box_width
(int) – Selection box width in px. If0
compute automatically to fit placeholderselection_infinite
(bool) – IfTrue
selection can rotate through bottom/topselection_option_border_color
(tuple, list, str, int,pygame.Color
) – Option border colorselection_option_border_width
(int) – Option border widthselection_option_font_color
(tuple, list, str, int,pygame.Color
) – Option font colorselection_option_font_size
(int, None) – Option font size. IfNone
use the 75% of the widget font sizeselection_option_font
(str,pathlib.Path
,pygame.font.Font
) – Option font. IfNone
use the same font as the widgetselection_option_padding
(int, float, tuple, list ) – Selection padding. See padding stylingselection_option_selected_bgcolor
(tuple, list, str, int,pygame.Color
) – Selected option background colorselection_option_selected_font_color
(tuple, list, str, int,pygame.Color
) – Selected option font color
Note
All theme-related optional kwargs use the default Menu theme if not defined.
Note
This is applied only to the base Menu (not the currently displayed, stored in
_current
pointer); for such behaviour apply topygame_menu.menu.Menu.get_current()
object.Warning
Be careful with kwargs collision. Consider that all optional documented kwargs keys are removed from the object.
- Parameters
title (
Any
) – Drop select titleitems (
Union
[List
[Tuple
[Any
, …]],List
[str
]]) – Item list of the drop select; format[('Item1', a, b, c...), ('Item2', d, e, f...)]
default (
int
) – Index of default item to displaydropselect_id (
str
) – ID of the dropselectonchange (
Optional
[Callable
]) – Callback when changing the drop select itemonreturn (
Optional
[Callable
]) – Callback when pressing return on the selected itemonselect (
Optional
[Callable
[[bool
,Widget
,Menu
],Any
]]) – Function when selecting the widgetopen_middle (
bool
) – IfTrue
the selection box is opened in the middle of the menuplaceholder (
str
) – Text shown if no option is selected yetplaceholder_add_to_selection_box (
bool
) – IfTrue
adds the placeholder button to the selection boxkwargs – Optional keyword arguments
- Returns
Widget object
- Return type
- dropselect_multiple(title, items, default=None, dropselect_multiple_id='', max_selected=0, onchange=None, onreturn=None, onselect=None, open_middle=False, placeholder='Select an option', placeholder_add_to_selection_box=True, placeholder_selected='{0} selected', selection_placeholder_format='total', **kwargs)[source]
Add a dropselect multiple to the Menu: Drop select multiple is a drop select which can select many options at the same time. This drops a vertical frame if requested.
The items of the DropSelectMultiple are:
items = [('Item1', a, b, c...), ('Item2', d, e, f...), ('Item3', g, h, i...)]
The callbacks receive the current selected items (tuple) and the indices (tuple), where
selected_item=widget.get_value()
andselected_index=widget.get_index()
:onchange((selected_item, selected_index), **kwargs) onreturn((selected_item, selected_index), **kwargs)
For example, if
selected_index=[0, 2]
thenselected_item=[('Item1', a, b, c...), ('Item3', g, h, i...)]
.If
onselect
is defined, the callback is executed as follows, whereselected
is a boolean representing the selected status:onselect(selected, widget, menu)
- kwargs (Optional)
align
(str) – Widget alignmentbackground_color
(tuple, list, str, int,pygame.Color
,pygame_menu.baseimage.BaseImage
) – Color of the background.None
for no-colorbackground_inflate
(tuple, list) – Inflate background on x-axis and y-axis (x, y) in pxborder_color
(tuple, list, str, int,pygame.Color
) – Widget border color.None
for no-colorborder_inflate
(tuple, list) – Widget border inflate on x-axis and y-axis (x, y) in pxborder_position
(str, tuple, list) – Widget border positioning. It can be a single position, or a tuple/list of positions. Only are accepted: north, south, east, and west. Seepygame_menu.locals
border_width
(int) – Border width in px. If0
disables the bordercursor
(int,pygame.cursors.Cursor
, None) – Cursor of the widget if the mouse is placed overfont_background_color
(tuple, list, str, int,pygame.Color
, None) – Widget font background colorfont_color
(tuple, list, str, int,pygame.Color
) – Widget font colorfont_name
(str,pathlib.Path
,pygame.font.Font
) – Widget font pathfont_shadow_color
(tuple, list, str, int,pygame.Color
) – Font shadow colorfont_shadow_offset
(int) – Font shadow offset in pxfont_shadow_position
(str) – Font shadow position, see locals for positionfont_shadow
(bool) – Font shadow is enabled or disabledfont_size
(int) – Font size of the widgetmargin
(tuple, list) – Widget (left, bottom) margin in pxpadding
(int, float, tuple, list) – Widget padding according to CSS rules. General shape: (top, right, bottom, left)readonly_color
(tuple, list, str, int,pygame.Color
) – Color of the widget if readonly modereadonly_selected_color
(tuple, list, str, int,pygame.Color
) – Color of the widget if readonly mode and is selectedselection_color
(tuple, list, str, int,pygame.Color
) – Color of the selected widget; only affects the font colorselection_effect
(pygame_menu.widgets.core.Selection
) – Widget selection effecttab_size
(int) – Width of a tab character
- kwargs for modifying selection box/option style (Optional)
scrollbar_color
(tuple, list, str, int,pygame.Color
) – Scrollbar colorscrollbar_cursor
(int,pygame.cursors.Cursor
, None) – Cursor of the scrollbars if the mouse is placed overscrollbar_shadow_color
(tuple, list, str, int,pygame.Color
) – Color of the shadow of each scrollbarscrollbar_shadow_offset
(int) – Offset of the scrollbar shadow in pxscrollbar_shadow_position
(str) – Position of the scrollbar shadow. Seepygame_menu.locals
scrollbar_shadow
(bool) – Indicate if a shadow is drawn on each scrollbarscrollbar_slider_color
(tuple, list, str, int,pygame.Color
) – Color of the slidersscrollbar_slider_hover_color
(tuple, list, str, int,pygame.Color
) – Color of the slider if hovered or clickedscrollbar_slider_pad
(int, float) – Space between slider and scrollbars borders in pxscrollbar_thick
(int) – Scrollbar thickness in pxscrollbars
(str) – Scrollbar position. Seepygame_menu.locals
selection_box_arrow_color
(tuple, list, str, int,pygame.Color
) – Selection box arrow colorselection_box_arrow_margin
(tuple) – Selection box arrow margin (left, right, vertical) in pxselection_box_bgcolor
(tuple, list, str, int,pygame.Color
) – Selection box background colorselection_box_border_color
(tuple, list, str, int,pygame.Color
) – Selection box border colorselection_box_border_width
(int) – Selection box border widthselection_box_height
(int) – Selection box height, counted as how many options are packed before showing scrollselection_box_inflate
(tuple) – Selection box inflate on x-axis and y-axis in pxselection_box_margin
(tuple, list) – Selection box on x-axis and y-axis (x, y) margin from title in pxselection_box_text_margin
(int) – Selection box text margin (left) in pxselection_box_width
(int) – Selection box width in px. If0
compute automatically to fit placeholderselection_infinite
(bool) – IfTrue
selection can rotate through bottom/topselection_option_active_bgcolor
(tuple, list, str, int,pygame.Color
) – Active option(s) background color; active options is the currently active (by user)selection_option_active_font_color
(tuple, list, str, int,pygame.Color
) – Active option(s) font colorselection_option_border_color
(tuple, list, str, int,pygame.Color
) – Option border colorselection_option_border_width
(int) – Option border widthselection_option_font_color
(tuple, list, str, int,pygame.Color
) – Option font colorselection_option_font_size
(int, None) – Option font size. IfNone
use the 75% of the widget font sizeselection_option_font
(str,pathlib.Path
,pygame.font.Font
) – Option font. IfNone
use the same font as the widgetselection_option_padding
(int, float, tuple, list) – Selection padding. See padding stylingselection_option_selected_bgcolor
(tuple, list, str, int,pygame.Color
) – Selected option background colorselection_option_selected_box_border
(int) – Box border width in pxselection_option_selected_box_color
(tuple, list, str, int,pygame.Color
) – Box colorselection_option_selected_box_height
(int, float) – Height of the selection box relative to the options heightselection_option_selected_box_margin
(tuple, list) – Option box margin (left, right, vertical) in pxselection_option_selected_box
(bool) – Draws a box in the selected option(s)selection_option_selected_font_color
(tuple, list, str, int,pygame.Color
) – Selected option font color
Note
All theme-related optional kwargs use the default Menu theme if not defined.
Note
This is applied only to the base Menu (not the currently displayed, stored in
_current
pointer); for such behaviour apply topygame_menu.menu.Menu.get_current()
object.Warning
Be careful with kwargs collision. Consider that all optional documented kwargs keys are removed from the object.
- Parameters
title (
Any
) – Drop select titleitems (
Union
[List
[Tuple
[Any
, …]],List
[str
]]) – Item list of the drop select; format[('Item1', a, b, c...), ('Item2', d, e, f...)]
default (
Union
[int
,List
[int
],None
]) – Index(es) of default item(s) to display. IfNone
no item is selecteddropselect_multiple_id (
str
) – ID of the dropselect multiplemax_selected (
int
) – Max items to be selected. If0
there’s no limitonchange (
Optional
[Callable
]) – Callback when changing the drop select itemonreturn (
Optional
[Callable
]) – Callback when pressing return on the selected itemonselect (
Optional
[Callable
[[bool
,Widget
,Menu
],Any
]]) – Function when selecting the widgetopen_middle (
bool
) – IfTrue
the selection box is opened in the middle of the menuplaceholder (
str
) – Text shown if no option is selected yetplaceholder_add_to_selection_box (
bool
) – IfTrue
adds the placeholder button to the selection boxplaceholder_selected (
str
) – Text shown if option is selected. Accepts the number of selected optionsselection_placeholder_format (
Union
[Literal
[‘total’, ‘comma-list’, ‘hyphen-list’],Callable
[[List
[str
]],str
]]) – Format of the string replaced inplaceholder_selected
. Can be a predefined string type (“total”, “comma-list”, “hyphen-list”, or any other string which will join the list) or a function that receives the list of selected items and returns a stringkwargs – Optional keyword arguments
- Returns
Widget object
- Return type
- frame_h(width, height, frame_id='', **kwargs)[source]
Adds a horizontal frame to the Menu. Frame is a widget container that packs many widgets within. All contained widgets have a floating position, and use only 1 position in column/row layout.
frame.pack(W1, alignment=ALIGN_LEFT, vertical_position=POSITION_NORTH) frame.pack(W2, alignment=ALIGN_LEFT, vertical_position=POSITION_CENTER) frame.pack(W3, alignment=ALIGN_LEFT, vertical_position=POSITION_SOUTH) ... ---------------- |W1 | | W2 ... | | W3 | ----------------
- kwargs (Optional)
align
(str) – Widget alignmentbackground_color
(tuple, list, str, int,pygame.Color
,pygame_menu.baseimage.BaseImage
) – Color of the background.None
for no-colorbackground_inflate
(tuple, list) – Inflate background on x-axis and y-axis (x, y) in pxborder_color
(tuple, list, str, int,pygame.Color
) – Widget border color.None
for no-colorborder_inflate
(tuple, list) – Widget border inflate on x-axis and y-axis (x, y) in pxborder_position
(str, tuple, list) – Widget border positioning. It can be a single position, or a tuple/list of positions. Only are accepted: north, south, east, and west. Seepygame_menu.locals
border_width
(int) – Border width in px. If0
disables the bordercursor
(int,pygame.cursors.Cursor
, None) – Cursor of the frame if the mouse is placed overmargin
(tuple, list) – Widget (left, bottom) margin in pxmax_height
(int) – Max height in px. If lower than the frame height a scrollbar will appear on vertical axis.None
by default (same height)max_width
(int) – Max width in px. If lower than the frame width a scrollbar will appear on horizontal axis.None
by default (same width)padding
(int, float, tuple, list) – Widget padding according to CSS rules. General shape: (top, right, bottom, left)scrollarea_color
(tuple, list, str, int,pygame.Color
,pygame_menu.baseimage.BaseImage
,None) – Scroll area color. IfNone
area is transparentscrollbar_color
(tuple, list, str, int,pygame.Color
) – Scrollbar colorscrollbar_cursor
(int,pygame.cursors.Cursor
, None) – Cursor of the scrollbars if the mouse is placed overscrollbar_shadow_color
(tuple, list, str, int,pygame.Color
) – Color of the shadow of each scrollbarscrollbar_shadow_offset
(int) – Offset of the scrollbar shadow in pxscrollbar_shadow_position
(str) – Position of the scrollbar shadow. Seepygame_menu.locals
scrollbar_shadow
(bool) – Indicate if a shadow is drawn on each scrollbarscrollbar_slider_color
(tuple, list, str, int,pygame.Color
) – Color of the slidersscrollbar_slider_hover_color
(tuple, list, str, int,pygame.Color
) – Color of the slider if hovered or clickedscrollbar_slider_pad
(int, float) – Space between slider and scrollbars borders in pxscrollbar_thick
(int) – Scrollbar thickness in pxscrollbars
(str) – Scrollbar position. Seepygame_menu.locals
tab_size
(int) – Width of a tab character
Note
All theme-related optional kwargs use the default Menu theme if not defined.
Note
If horizontal frame contains a scrollarea (setting
max_height
ormax_width
less than size) padding will be set at zero.Note
Packing applies a virtual translation to the widget, previous translation is not modified.
Note
Widget floating is also considered within frames. If a widget is floating, it does not add any size to the respective positioning.
Note
The Frame size created with this method does consider the padding. Thus, if Frame is created with
width=100
,height=200
andpadding=25
the final internal size iswidth=50
andheight=150
.Note
This is applied only to the base Menu (not the currently displayed, stored in
_current
pointer); for such behaviour apply topygame_menu.menu.Menu.get_current()
object.
- frame_v(width, height, frame_id='', **kwargs)[source]
Adds a vertical frame to the Menu. Frame is a widget container that packs many widgets within. All contained widgets have a floating position, and use only 1 position in column/row layout.
frame.pack(W1, alignment=ALIGN_LEFT) frame.pack(W2, alignment=ALIGN_CENTER) frame.pack(W3, alignment=ALIGN_RIGHT) ... -------- |W1 | | W2 | | W3| | ... | --------
- kwargs (Optional)
align
(str) – Widget alignmentbackground_color
(tuple, list, str, int,pygame.Color
,pygame_menu.baseimage.BaseImage
) – Color of the background.None
for no-colorbackground_inflate
(tuple, list) – Inflate background on x-axis and y-axis (x, y) in pxborder_color
(tuple, list, str, int,pygame.Color
) – Widget border color.None
for no-colorborder_inflate
(tuple, list) – Widget border inflate on x-axis and y-axis (x, y) in pxborder_position
(str, tuple, list) – Widget border positioning. It can be a single position, or a tuple/list of positions. Only are accepted: north, south, east, and west. Seepygame_menu.locals
border_width
(int) – Border width in px. If0
disables the bordercursor
(int,pygame.cursors.Cursor
, None) – Cursor of the frame if the mouse is placed overmargin
(tuple, list) – Widget (left, bottom) margin in pxmax_height
(int) – Max height in px. If lower than the frame height a scrollbar will appear on vertical axis.None
by default (same height)max_width
(int) – Max width in px. If lower than the frame width a scrollbar will appear on horizontal axis.None
by default (same width)padding
(int, float, tuple, list) – Widget padding according to CSS rules. General shape: (top, right, bottom, left)scrollarea_color
(tuple, list, str, int,pygame.Color
,pygame_menu.baseimage.BaseImage
,None) – Scroll area color. IfNone
area is transparentscrollbar_color
(tuple, list, str, int,pygame.Color
) – Scrollbar colorscrollbar_cursor
(int,pygame.cursors.Cursor
, None) – Cursor of the scrollbars if the mouse is placed overscrollbar_shadow_color
(tuple, list, str, int,pygame.Color
) – Color of the shadow of each scrollbarscrollbar_shadow_offset
(int) – Offset of the scrollbar shadow in pxscrollbar_shadow_position
(str) – Position of the scrollbar shadow. Seepygame_menu.locals
scrollbar_shadow
(bool) – Indicate if a shadow is drawn on each scrollbarscrollbar_slider_color
(tuple, list, str, int,pygame.Color
) – Color of the slidersscrollbar_slider_hover_color
(tuple, list, str, int,pygame.Color
) – Color of the slider if hovered or clickedscrollbar_slider_pad
(int, float) – Space between slider and scrollbars borders in pxscrollbar_thick
(int) – Scrollbar thickness in pxscrollbars
(str) – Scrollbar position. Seepygame_menu.locals
tab_size
(int) – Width of a tab character
Note
All theme-related optional kwargs use the default Menu theme if not defined.
Note
If vertical frame contains a scrollarea (setting
max_height
ormax_width
less than size) padding will be set at zero.Note
Packing applies a virtual translation to the widget, previous translation is not modified.
Note
Widget floating is also considered within frames. If a widget is floating, it does not add any size to the respective positioning.
Note
The Frame size created with this method does consider the padding. Thus, if Frame is created with
width=100
,height=200
andpadding=25
the final internal size iswidth=50
andheight=150
.Note
This is applied only to the base Menu (not the currently displayed, stored in
_current
pointer); for such behaviour apply topygame_menu.menu.Menu.get_current()
object.
- generic_widget(widget, configure_defaults=False)[source]
Add generic widget to the Menu.
Note
The widget should be fully configured by the user: font, padding, etc.
Note
This is applied only to the base Menu (not the currently displayed, stored in
_current
pointer); for such behaviour apply topygame_menu.menu.Menu.get_current()
object.Warning
Unintended behaviours may happen while using this method, use only with caution; specially while creating nested submenus with buttons.
- image(image_path, angle=0, image_id='', onselect=None, scale=(1, 1), scale_smooth=True, selectable=False, **kwargs)[source]
Add a simple image to the Menu.
If
onselect
is defined, the callback is executed as follows, whereselected
is a boolean representing the selected status:onselect(selected, widget, menu)
- kwargs (Optional)
align
(str) – Widget alignmentbackground_color
(tuple, list, str, int,pygame.Color
,pygame_menu.baseimage.BaseImage
) – Color of the background.None
for no-colorbackground_inflate
(tuple, list) – Inflate background on x-axis and y-axis (x, y) in pxborder_color
(tuple, list, str, int,pygame.Color
) – Widget border color.None
for no-colorborder_inflate
(tuple, list) – Widget border inflate on x-axis and y-axis (x, y) in pxborder_position
(str, tuple, list) – Widget border positioning. It can be a single position, or a tuple/list of positions. Only are accepted: north, south, east, and west. Seepygame_menu.locals
border_width
(int) – Border width in px. If0
disables the bordercursor
(int,pygame.cursors.Cursor
, None) – Cursor of the widget if the mouse is placed overmargin
(tuple, list) – Widget (left, bottom) margin in pxpadding
(int, float, tuple, list) – Widget padding according to CSS rules. General shape: (top, right, bottom, left)selection_color
(tuple, list, str, int,pygame.Color
) – Color of the selected widget; only affects the font colorselection_effect
(pygame_menu.widgets.core.Selection
) – Widget selection effect. Applied only ifselectable
isTrue
Note
All theme-related optional kwargs use the default Menu theme if not defined.
Note
This is applied only to the base Menu (not the currently displayed, stored in
_current
pointer); for such behaviour apply topygame_menu.menu.Menu.get_current()
object.- Parameters
image_path (
Union
[str
,Path
,BaseImage
,BytesIO
]) – Path of the image (file) or a BaseImage object. If BaseImage object is provided the angle and scale are ignoredangle (
Union
[int
,float
]) – Angle of the image in degrees (clockwise)image_id (
str
) – ID of the imageonselect (
Optional
[Callable
[[bool
,Widget
,Menu
],Any
]]) – Callback executed when selecting the widget; only executed ifselectable
isTrue
scale (
Union
[Tuple
[Union
[int
,float
],Union
[int
,float
]],List
[Union
[int
,float
]]]) – Scale of the image on x-axis and y-axis (x, y)scale_smooth (
bool
) – Scale is smoothedselectable (
bool
) – Image accepts user selectionkwargs – Optional keyword arguments
- Returns
Widget object
- Return type
- label(title, label_id='', max_char=0, onselect=None, selectable=False, **kwargs)[source]
Add a simple text to the Menu.
If
onselect
is defined, the callback is executed as follows, whereselected
is a boolean representing the selected status:onselect(selected, widget, menu)
- kwargs (Optional)
align
(str) – Widget alignmentbackground_color
(tuple, list, str, int,pygame.Color
,pygame_menu.baseimage.BaseImage
) – Color of the background.None
for no-colorbackground_inflate
(tuple, list) – Inflate background on x-axis and y-axis (x, y) in pxborder_color
(tuple, list, str, int,pygame.Color
) – Widget border color.None
for no-colorborder_inflate
(tuple, list) – Widget border inflate on x-axis and y-axis (x, y) in pxborder_position
(str, tuple, list) – Widget border positioning. It can be a single position, or a tuple/list of positions. Only are accepted: north, south, east, and west. Seepygame_menu.locals
border_width
(int) – Border width in px. If0
disables the bordercursor
(int,pygame.cursors.Cursor
, None) – Cursor of the widget if the mouse is placed overfont_background_color
(tuple, list, str, int,pygame.Color
, None) – Widget font background colorfont_color
(tuple, list, str, int,pygame.Color
) – Widget font colorfont_name
(str,pathlib.Path
,pygame.font.Font
) – Widget font pathfont_shadow_color
(tuple, list, str, int,pygame.Color
) – Font shadow colorfont_shadow_offset
(int) – Font shadow offset in pxfont_shadow_position
(str) – Font shadow position, see locals for positionfont_shadow
(bool) – Font shadow is enabled or disabledfont_size
(int) – Font size of the widgetmargin
(tuple, list) – Widget (left, bottom) margin in pxpadding
(int, float, tuple, list) – Widget padding according to CSS rules. General shape: (top, right, bottom, left)selection_color
(tuple, list, str, int,pygame.Color
) – Color of the selected widget; only affects the font colorselection_effect
(pygame_menu.widgets.core.Selection
) – Widget selection effect. Applied only ifselectable
isTrue
tab_size
(int) – Width of a tab characterunderline_color
(tuple, list, str, int,pygame.Color
, None) – Color of the underline. IfNone
use the same color of the textunderline_offset
(int) – Vertical offset in px.2
by defaultunderline_width
(int) – Underline width in px.2
by defaultunderline
(bool) – Enables text underline, using a properly placed decoration.False
by default
Note
All theme-related optional kwargs use the default Menu theme if not defined.
Note
This is applied only to the base Menu (not the currently displayed, stored in
_current
pointer); for such behaviour apply topygame_menu.menu.Menu.get_current()
object.- Parameters
title (
Any
) – Text to be displayedlabel_id (
str
) – ID of the labelmax_char (
int
) – Split the title in several labels if the string length exceedsmax_char
;0
: don’t split,-1
: split to Menu widthonselect (
Optional
[Callable
[[bool
,Widget
,Menu
],Any
]]) – Callback executed when selecting the widget; only executed ifselectable
isTrue
selectable (
bool
) – Label accepts user selection; useful to move along the Menu using label selectionkwargs – Optional keyword arguments
- Returns
Widget object, or List of widgets if the text overflows
- Return type
pygame_menu.widgets.Label
,typing.List
[pygame_menu.widgets.Label
]
- menu_link(menu, link_id='')[source]
Adds a link to another Menu. The behaviour is similar to a button, but this widget is invisible, and cannot be selectable.
Added menus can be opened using the
.open()
method. Opened menus change the state of the parent Menu (the current pointer).Note
This is applied only to the base Menu (not the currently displayed, stored in
_current
pointer); for such behaviour apply topygame_menu.menu.Menu.get_current()
object.- Parameters
- Returns
Menu link widget
- Return type
- none_widget(widget_id='')[source]
Add a none widget to the Menu.
Note
This widget is useful to fill column/rows layout without compromising any visuals. Also it can be used to store information or even to add a
draw_callback
function to it for being called on each Menu draw.Note
This is applied only to the base Menu (not the currently displayed, stored in
_current
pointer); for such behaviour apply topygame_menu.menu.Menu.get_current()
object.- Parameters
widget_id (
str
) – Widget ID- Returns
Widget object
- Return type
- selector(title, items, default=0, onchange=None, onreturn=None, onselect=None, selector_id='', style='classic', **kwargs)[source]
Add a selector to the Menu: several items and two functions that are executed when changing the selector (left/right) and pressing return button on the selected item.
The items of the selector are like:
items = [('Item1', a, b, c...), ('Item2', d, e, f...)]
The callbacks receive the current selected item, its index in the list, the associated arguments, and all unknown keyword arguments, where
selected_item=widget.get_value()
andselected_index=widget.get_index()
:onchange((selected_item, selected_index), a, b, c..., **kwargs) onreturn((selected_item, selected_index), a, b, c..., **kwargs)
For example, if
selected_index=0
thenselected_item=('Item1', a, b, c...)
.If
onselect
is defined, the callback is executed as follows, whereselected
is a boolean representing the selected status:onselect(selected, widget, menu)
- kwargs (Optional)
align
(str) – Widget alignmentbackground_color
(tuple, list, str, int,pygame.Color
,pygame_menu.baseimage.BaseImage
) – Color of the background.None
for no-colorbackground_inflate
(tuple, list) – Inflate background on x-axis and y-axis (x, y) in pxborder_color
(tuple, list, str, int,pygame.Color
) – Widget border color.None
for no-colorborder_inflate
(tuple, list) – Widget border inflate on x-axis and y-axis (x, y) in pxborder_position
(str, tuple, list) – Widget border positioning. It can be a single position, or a tuple/list of positions. Only are accepted: north, south, east, and west. Seepygame_menu.locals
border_width
(int) – Border width in px. If0
disables the bordercursor
(int,pygame.cursors.Cursor
, None) – Cursor of the widget if the mouse is placed overfont_background_color
(tuple, list, str, int,pygame.Color
, None) – Widget font background colorfont_color
(tuple, list, str, int,pygame.Color
) – Widget font colorfont_name
(str,pathlib.Path
,pygame.font.Font
) – Widget font pathfont_shadow_color
(tuple, list, str, int,pygame.Color
) – Font shadow colorfont_shadow_offset
(int) – Font shadow offset in pxfont_shadow_position
(str) – Font shadow position, see locals for positionfont_shadow
(bool) – Font shadow is enabled or disabledfont_size
(int) – Font size of the widgetmargin
(tuple, list) – Widget (left, bottom) margin in pxpadding
(int, float, tuple, list) – Widget padding according to CSS rules. General shape: (top, right, bottom, left)readonly_color
(tuple, list, str, int,pygame.Color
) – Color of the widget if readonly modereadonly_selected_color
(tuple, list, str, int,pygame.Color
) – Color of the widget if readonly mode and is selectedselection_color
(tuple, list, str, int,pygame.Color
) – Color of the selected widget; only affects the font colorselection_effect
(pygame_menu.widgets.core.Selection
) – Widget selection effectstyle_fancy_arrow_color
(tuple, list, str, int,pygame.Color
) – Arrow color of fancy stylestyle_fancy_arrow_margin
(tuple, list) – Margin of arrows on x-axis and y-axis in px; format: (left, right, vertical)style_fancy_bgcolor
(tuple, list, str, int,pygame.Color
) – Background color of fancy stylestyle_fancy_bordercolor
(tuple, list, str, int,pygame.Color
) – Border color of fancy stylestyle_fancy_borderwidth
(int) – Border width of fancy style;1
by defaultstyle_fancy_box_inflate
(tuple, list) – Box inflate of fancy style on x-axis and y-axis (x, y) in pxstyle_fancy_box_margin
(tuple, list) – Box margin on x-axis and y-axis (x, y) in fancy style from title in pxtab_size
(int) – Width of a tab character
Note
All theme-related optional kwargs use the default Menu theme if not defined.
Note
This is applied only to the base Menu (not the currently displayed, stored in
_current
pointer); for such behaviour apply topygame_menu.menu.Menu.get_current()
object.Warning
Be careful with kwargs collision. Consider that all optional documented kwargs keys are removed from the object.
- Parameters
title (
Any
) – Title of the selectoritems (
Union
[List
[Tuple
[Any
, …]],List
[str
]]) – Item list of the selector; format[('Item1', a, b, c...), ('Item2', d, e, f...)]
default (
int
) – Index of default item to displayonchange (
Optional
[Callable
]) – Callback executed when when changing the selectoronreturn (
Optional
[Callable
]) – Callback executed when pressing return buttononselect (
Optional
[Callable
[[bool
,Widget
,Menu
],Any
]]) – Callback executed when selecting the widgetselector_id (
str
) – ID of the selectorstyle (
Literal
[‘classic’, ‘fancy’]) – Selector style (visual)kwargs – Optional keyword arguments
- Returns
Widget object
- Return type
- surface(surface, surface_id='', onselect=None, selectable=False, **kwargs)[source]
Add a surface widget to the Menu.
If
onselect
is defined, the callback is executed as follows, whereselected
is a boolean representing the selected status:onselect(selected, widget, menu)
- kwargs (Optional)
align
(str) – Widget alignmentbackground_color
(tuple, list, str, int,pygame.Color
,pygame_menu.baseimage.BaseImage
) – Color of the background.None
for no-colorbackground_inflate
(tuple, list) – Inflate background on x-axis and y-axis (x, y) in pxborder_color
(tuple, list, str, int,pygame.Color
) – Widget border color.None
for no-colorborder_inflate
(tuple, list) – Widget border inflate on x-axis and y-axis (x, y) in pxborder_position
(str, tuple, list) – Widget border positioning. It can be a single position, or a tuple/list of positions. Only are accepted: north, south, east, and west. Seepygame_menu.locals
border_width
(int) – Border width in px. If0
disables the bordercursor
(int,pygame.cursors.Cursor
, None) – Cursor of the widget if the mouse is placed overmargin
(tuple, list) – Widget (left, bottom) margin in pxpadding
(int, float, tuple, list) – Widget padding according to CSS rules. General shape: (top, right, bottom, left)selection_color
(tuple, list, str, int,pygame.Color
) – Color of the selected widget; only affects the font colorselection_effect
(pygame_menu.widgets.core.Selection
) – Widget selection effect. Applied only ifselectable
isTrue
Note
All theme-related optional kwargs use the default Menu theme if not defined.
Note
This is applied only to the base Menu (not the currently displayed, stored in
_current
pointer); for such behaviour apply topygame_menu.menu.Menu.get_current()
object.- Parameters
- Returns
Widget object
- Return type
- table(table_id='', **kwargs)[source]
Adds a Table to the Menu. A table is a frame which can pack widgets in a structured way.
- kwargs (Optional)
align
(str) – Widget alignmentbackground_color
(tuple, list, str, int,pygame.Color
,pygame_menu.baseimage.BaseImage
) – Color of the background.None
for no-colorbackground_inflate
(tuple, list) – Inflate background on x-axis and y-axis (x, y) in pxborder_color
(tuple, list, str, int,pygame.Color
) – Widget border color.None
for no-colorborder_inflate
(tuple, list) – Widget border inflate on x-axis and y-axis (x, y) in pxborder_position
(str, tuple, list) – Widget border positioning. It can be a single position, or a tuple/list of positions. Only are accepted: north, south, east, and west. Seepygame_menu.locals
border_width
(int) – Border width in px. If0
disables the bordercursor
(int,pygame.cursors.Cursor
, None) – Cursor of the frame if the mouse is placed overfont_background_color
(tuple, list, str, int,pygame.Color
, None) – Widget font background colorfont_color
(tuple, list, str, int,pygame.Color
) – Widget font colorfont_name
(str,pathlib.Path
,pygame.font.Font
) – Widget font pathfont_shadow_color
(tuple, list, str, int,pygame.Color
) – Font shadow colorfont_shadow_offset
(int) – Font shadow offset in pxfont_shadow_position
(str) – Font shadow position, see locals for positionfont_shadow
(bool) – Font shadow is enabled or disabledfont_size
(int) – Font size of the widgetmargin
(tuple, list) – Widget (left, bottom) margin in pxmax_height
(int) – Max height in px. If lower than the frame height a scrollbar will appear on vertical axis.None
by default (same height)max_width
(int) – Max width in px. If lower than the frame width a scrollbar will appear on horizontal axis.None
by default (same width)padding
(int, float, tuple, list) – Widget padding according to CSS rules. General shape: (top, right, bottom, left)tab_size
(int) – Width of a tab character
Note
All theme-related optional kwargs use the default Menu theme if not defined.
Note
This is applied only to the base Menu (not the currently displayed, stored in
_current
pointer); for such behaviour apply topygame_menu.menu.Menu.get_current()
object.- Parameters
table_id (
str
) – ID of the tablekwargs – Optional keyword arguments
- Returns
Widget object
- Return type
- text_input(title, default='', copy_paste_enable=True, cursor_selection_enable=True, cursor_size=None, input_type='input-text', input_underline='', input_underline_len=0, maxchar=0, maxwidth=0, onchange=None, onreturn=None, onselect=None, password=False, textinput_id='', valid_chars=None, **kwargs)[source]
Add a text input to the Menu: free text area and two functions that execute when changing the text and pressing return button on the element.
The callbacks receive the current value and all unknown keyword arguments, where
current_text=widget.get_value
:onchange(current_text, **kwargs) onreturn(current_text, **kwargs)
If
onselect
is defined, the callback is executed as follows, whereselected
is a boolean representing the selected status:onselect(selected, widget, menu)
- kwargs (Optional)
align
(str) – Widget alignmentbackground_color
(tuple, list, str, int,pygame.Color
,pygame_menu.baseimage.BaseImage
) – Color of the background.None
for no-colorbackground_inflate
(tuple, list) – Inflate background on x-axis and y-axis (x, y) in pxborder_color
(tuple, list, str, int,pygame.Color
) – Widget border color.None
for no-colorborder_inflate
(tuple, list) – Widget border inflate on x-axis and y-axis (x, y) in pxborder_position
(str, tuple, list) – Widget border positioning. It can be a single position, or a tuple/list of positions. Only are accepted: north, south, east, and west. Seepygame_menu.locals
border_width
(int) – Border width in px. If0
disables the bordercursor
(int,pygame.cursors.Cursor
, None) – Cursor of the widget if the mouse is placed overfont_background_color
(tuple, list, str, int,pygame.Color
, None) – Widget font background colorfont_color
(tuple, list, str, int,pygame.Color
) – Widget font colorfont_name
(str,pathlib.Path
,pygame.font.Font
) – Widget font pathfont_shadow_color
(tuple, list, str, int,pygame.Color
) – Font shadow colorfont_shadow_offset
(int) – Font shadow offset in pxfont_shadow_position
(str) – Font shadow position, see locals for positionfont_shadow
(bool) – Font shadow is enabled or disabledfont_size
(int) – Font size of the widgethistory
(int) - Maximum number of editions stored. If0
the feature is disabled.50
by defaultinput_underline_vmargin
(int) – Vertical margin of underline in pxmargin
(tuple, list) – Widget (left, bottom) margin in pxmaxwidth_dynamically_update
(bool) - Dynamically update maxwidth depending on char size.True
by defaultpadding
(int, float, tuple, list) – Widget padding according to CSS rules. General shape: (top, right, bottom, left)password_char
(str) - Character used by password type."*"
by defaultreadonly_color
(tuple, list, str, int,pygame.Color
) – Color of the widget if readonly modereadonly_selected_color
(tuple, list, str, int,pygame.Color
) – Color of the widget if readonly mode and is selectedrepeat_keys_initial_ms
(int, float) - Time in ms before keys are repeated when held in ms.400
by defaultrepeat_keys_interval_ms
(int, float) - Interval between key press repetition when held in ms.50
by defaultrepeat_mouse_interval_ms
(int, float) - Interval between mouse events when held in ms.400
by defaultselection_color
(tuple, list, str, int,pygame.Color
) – Color of the selected widget; only affects the font colorselection_effect
(pygame_menu.widgets.core.Selection
) – Widget selection effecttab_size
(int) – Width of a tab charactertext_ellipsis
(str) - Ellipsis text when overflow occurs (input length exceeds maxwidth)."..."
by default
Note
All theme-related optional kwargs use the default Menu theme if not defined.
Note
This is applied only to the base Menu (not the currently displayed, stored in
_current
pointer); for such behaviour apply topygame_menu.menu.Menu.get_current()
object.Warning
Be careful with kwargs collision. Consider that all optional documented kwargs keys are removed from the object.
- Parameters
title (
Any
) – Title of the text inputcopy_paste_enable (
bool
) – Enable text copy, paste and cutcursor_selection_enable (
bool
) – Enable text selection on inputcursor_size (
Optional
[Tuple
[int
,int
]]) – Size of the cursor (width, height) in px. IfNone
uses the default sizinginput_type (
str
) – Data type of the input. Seepygame_menu.locals
input_underline (
str
) – Underline characterinput_underline_len (
int
) – Total of characters to be drawn under the input. If0
this number is computed automatically to fit the fontmaxchar (
int
) – Maximum length of string, if 0 there’s no limitmaxwidth (
int
) – Maximum size of the text widget (in number of chars), if0
there’s no limitonchange (
Optional
[Callable
]) – Callback executed when changing the text inputonreturn (
Optional
[Callable
]) – Callback executed when pressing return on the text inputonselect (
Optional
[Callable
[[bool
,Widget
,Menu
],Any
]]) – Callback executed when selecting the widgetpassword (
bool
) – Text input is a passwordtextinput_id (
str
) – ID of the text inputvalid_chars (
Optional
[List
[str
]]) – List of authorized chars.None
if all chars are validkwargs – Optional keyword arguments
- Returns
Widget object
- Return type
- toggle_switch(title, default=0, onchange=None, onselect=None, toggleswitch_id='', single_click=True, state_text=('Off', 'On'), state_values=(False, True), width=150, **kwargs)[source]
Add a toggle switch to the Menu: It can switch between two states.
If user changes the status of the callback,
onchange
is fired:onchange(current_state_value, **kwargs)
If
onselect
is defined, the callback is executed as follows, whereselected
is a boolean representing the selected status:onselect(selected, widget, menu)
- kwargs (Optional)
align
(str) – Widget alignmentbackground_color
(tuple, list, str, int,pygame.Color
,pygame_menu.baseimage.BaseImage
) – Color of the background.None
for no-colorbackground_inflate
(tuple, list) – Inflate background on x-axis and y-axis (x, y) in pxborder_color
(tuple, list, str, int,pygame.Color
) – Widget border color.None
for no-colorborder_inflate
(tuple, list) – Widget border inflate on x-axis and y-axis (x, y) in pxborder_position
(str, tuple, list) – Widget border positioning. It can be a single position, or a tuple/list of positions. Only are accepted: north, south, east, and west. Seepygame_menu.locals
border_width
(int) – Border width in px. If0
disables the bordercursor
(int,pygame.cursors.Cursor
, None) – Cursor of the widget if the mouse is placed overfont_background_color
(tuple, list, str, int,pygame.Color
, None) – Widget font background colorfont_color
(tuple, list, str, int,pygame.Color
) – Widget font colorfont_name
(str,pathlib.Path
,pygame.font.Font
) – Widget font pathfont_shadow_color
(tuple, list, str, int,pygame.Color
) – Font shadow colorfont_shadow_offset
(int) – Font shadow offset in pxfont_shadow_position
(str) – Font shadow position, see locals for positionfont_shadow
(bool) – Font shadow is enabled or disabledfont_size
(int) – Font size of the widgetinfinite
(bool) – The state can rotate.False
by defaultmargin
(tuple, list) – Widget (left, bottom) margin in pxpadding
(int, float, tuple, list) – Widget padding according to CSS rules. General shape: (top, right, bottom, left)readonly_color
(tuple, list, str, int,pygame.Color
) – Color of the widget if readonly modereadonly_selected_color
(tuple, list, str, int,pygame.Color
) – Color of the widget if readonly mode and is selectedselection_color
(tuple, list, str, int,pygame.Color
) – Color of the selected widget; only affects the font colorselection_effect
(pygame_menu.widgets.core.Selection
) – Widget selection effectsingle_click_dir
(bool) - Direction of the change if only 1 click is pressed.True
for left direction (default),False
for rightslider_color
(tuple, list, str, int,pygame.Color
) – Color of the sliderslider_height_factor
(int, float) - Height of the slider (factor of the switch height).1
by defaultslider_thickness
(int) – Slider thickness in px.20
px by defaultslider_vmargin
(int, float) - Vertical margin of the slider (factor of the switch height).0
by defaultstate_color
(tuple) – 2-item color tuple for each statestate_text_font
(str,pathlib.Path
,pygame.font.Font
, None) - Font of the state text. IfNone
uses the widget font.None
by defaultstate_text_font_color
(tuple) – 2-item color tuple for each font state text colorstate_text_font_size
(str, None) – Font size of the state text. IfNone
uses the widget font sizestate_text_position
(tuple) - Position of the state text respect to the switch rect.(0.5, 0.5)
by defaultswitch_border_color
(tuple, list, str, int,pygame.Color
) – Switch border colorswitch_border_width
(int) – Switch border widthswitch_height
(int, float) – Height factor respect to the title font size heightswitch_margin
(tuple, list) – Switch on x-axis and y-axis (x, y) margin respect to the title of the widget in pxtab_size
(int) – Width of a tab character
Note
This method only handles two states. If you need more states (for example 3, or 4), prefer using
pygame_menu.widgets.ToggleSwitch
and add it as a generic widget.Note
All theme-related optional kwargs use the default Menu theme if not defined.
Note
This is applied only to the base Menu (not the currently displayed, stored in
_current
pointer); for such behaviour apply topygame_menu.menu.Menu.get_current()
object.Warning
Be careful with kwargs collision. Consider that all optional documented kwargs keys are removed from the object.
- Parameters
title (
Any
) – Title of the toggle switchdefault (
Union
[int
,bool
]) – Default state index of the switch; it can be0 (False)
or1 (True)
onchange (
Optional
[Callable
]) – Callback executed when when changing the state of the toggle switchonselect (
Optional
[Callable
[[bool
,Widget
,Menu
],Any
]]) – Callback executed when selecting the widgettoggleswitch_id (
str
) – Widget IDsingle_click (
bool
) – Changes the state of the switch with 1 click instead of finding the closest positionstate_values (
Tuple
[Any
, …]) – Value of each state of the switchwidth (
int
) – Width of the switch box in px
- Returns
Widget object
- Return type
- url(href, title='', **kwargs)[source]
Adds a Button url to the Menu. Clicking the widget will open the link. If
title
is defined, the link will not be written. For example:href='google.com', title=''
will write the link, buthref='google.com', title='Google'
will write ‘Google’ and opens ‘google.com’ if clicked.If
onselect
is defined, the callback is executed as follows, whereselected
is a boolean representing the selected status:onselect(selected, widget, menu)
- kwargs (Optional)
align
(str) – Widget alignmentbackground_color
(tuple, list, str, int,pygame.Color
,pygame_menu.baseimage.BaseImage
) – Color of the background.None
for no-colorbackground_inflate
(tuple, list) – Inflate background on x-axis and y-axis (x, y) in pxborder_color
(tuple, list, str, int,pygame.Color
) – Widget border color.None
for no-colorborder_inflate
(tuple, list) – Widget border inflate on x-axis and y-axis (x, y) in pxborder_position
(str, tuple, list) – Widget border positioning. It can be a single position, or a tuple/list of positions. Only are accepted: north, south, east, and west. Seepygame_menu.locals
border_width
(int) – Border width in px. If0
disables the bordercursor
(int,pygame.cursors.Cursor
, None) – Cursor of the widget if the mouse is placed over. By default isHAND
font_background_color
(tuple, list, str, int,pygame.Color
, None) – Widget font background colorfont_color
(tuple, list, str, int,pygame.Color
) – Widget font color. If not defined, usestheme.widget_url_color
font_name
(str,pathlib.Path
,pygame.font.Font
) – Widget font pathfont_shadow_color
(tuple, list, str, int,pygame.Color
) – Font shadow colorfont_shadow_offset
(int) – Font shadow offset in pxfont_shadow_position
(str) – Font shadow position, see locals for positionfont_shadow
(bool) – Font shadow is enabled or disabledfont_size
(int) – Font size of the widgetmargin
(tuple, list) – Widget (left, bottom) margin in pxpadding
(int, float, tuple, list) – Widget padding according to CSS rules. General shape: (top, right, bottom, left)selection_color
(tuple, list, str, int,pygame.Color
) – Color of the selected widget; only affects the font colorselection_effect
(pygame_menu.widgets.core.Selection
) – Widget selection effecttab_size
(int) – Width of a tab characterunderline_color
(tuple, list, str, int,pygame.Color
, None) – Color of the underline. IfNone
use the same color of the textunderline_offset
(int) – Vertical offset in px.2
by defaultunderline_width
(int) – Underline width in px.2
by defaultunderline
(bool) – Enables text underline, using a properly placed decoration.True
by default
Note
All theme-related optional kwargs use the default Menu theme if not defined.
Note
This is applied only to the base Menu (not the currently displayed, stored in
_current
pointer); for such behaviour apply topygame_menu.menu.Menu.get_current()
object.- Parameters
- Returns
Widget object, or List of widgets if the text overflows
- Return type
- vertical_margin(margin, margin_id='')[source]
Adds a vertical margin to the Menu.
Note
This is applied only to the base Menu (not the currently displayed, stored in
_current
pointer); for such behaviour apply topygame_menu.menu.Menu.get_current()
object.- Parameters
- Returns
Widget object
- Return type