Button¶
- class Button¶
Basically a rectangle (or rounded rectangle) with text printed on it
- Available shorthand actions are:
generate: Generates the element’s image data.update: Function to update an element via actions.
Element Properties
- property background_color: str | int | list | tuple[L, A] | tuple[R, G, B] | tuple[R, G, B, A] | None
- Color of the element background.Optional, defaults to
None
- property font_color: str | int | list | tuple[L, A] | tuple[R, G, B] | tuple[R, G, B, A]
- The color of the font.Optional, defaults to
"black"
- property outline_color: str | int | list | tuple[L, A] | tuple[R, G, B] | tuple[R, G, B, A] | None
- Color of the elements outline. Set to None to use no outline (i.e. the background color).Optional, defaults to
None
- property hold_action: str | Callable[[Element, InteractEvent, Any], Any] | None
- The function called when the element is held. Set to None to have nothing called. If set to a dict, the values for hold_action_data and hold_action_map will be overwritten if the respective key is present.Optional, defaults to
None
- property hold_release_action: str | Callable[[Element, InteractEvent, Any], Any] | None
- The function called when the element is released from being held down. This function is only available on devices with the HOLD_RELEASE feature. Set to None to have nothing called. If set to a dict, the values for hold_release_action_data and hold_release_action_map will be overwritten if the respective key is present.Optional, defaults to
None
- property tap_action: str | Callable[[Element, InteractEvent, Any], Any] | None
- The function called when the element is tapped. Set to None to have nothing called. If set to a dict, the values for tap_action_data and tap_action_map will be overwritten if the respective key is present.Optional, defaults to
None
- property feedback_duration: duration
- Duration of the element’s feedback function The time an element will stay in ‘feedback state’, before returning to its normal state. Can be set to a string, which will be parsed to the right amount of seconds.Optional, defaults to
0.75
- property fit_text: bool
- Adjusts the font size automatically to make it fit. If true,
font_sizewill be used as a minimum allowed font_size.Optional, defaults toFalse
- property font
- The path to the element’s font. If set to a shorthand font, the path will automatically be parsed.Optional, defaults to
"default"
- property font_size: str | int | float
- The size of the font.Optional, defaults to
"H*0.036"
- property margins: tuple[int, int, int, int]
- The text margins. Always returns a 4 tuple, but can be set to a single number, or two/three/four item iterable. Same as css margins, so the values are returned as (top,right,bottom,left), and set according to css margins (https://www.w3schools.com/css/css_margin.asp).Optional, defaults to
0
- property multiline: bool
- Allows the button to try and fit its text over multiple lines. May not work very well with the settings that automatically set the font size.Optional, defaults to
False
- property outline_width: str | int | float
- The width of the outline of the background rectangle.Optional, defaults to
1
- property radius: str | int | float
- Corner radius of the encapsulating rectangle. Currently only accepts integers.Optional, defaults to
0
- property resize: bool | str | int | float
- Tracks the
font_sizeand adjusts it to fit. Theresizevalue updates and will be used as a starting point for the next update. If not False, will use this value as a minimum allowed size for any text displayed. Changes the font_size parameter when needed, such that the text size won’t change with every new text. Sizes are not saved upon resets, so finding a good size takes a few changes. The same goes when the element is resized.Optional, defaults toFalse
- property text: str
- The current text displayed on the button. Setting this attribute automatically converts the value into a string.Optional, defaults to
""
- property text_anchor_alignment: tuple[Literal[None, 'l', 'm', 'r', 's'], Literal[None, 'a', 't', 'm', 's', 'b', 'd']]
- Alignment of the textAnchor as (horizontal,vertical). Leave (one of) None to determine the anchor from text_x_position or text_y_position respectively. See https://pillow.readthedocs.io/en/stable/handbook/text-anchors.html#text-anchors for possible values, only accepts shorthands.Optional, defaults to
(None, None)
- property text_x_position: int | Literal['l', 'm', 'r', 's']
- Horizontal alignment of the text. Can be top, bottom or center, a Pillow textanchor (shorthand and longhand), a pssm dimensional string or an integer.Optional, defaults to
"center"
- property text_y_position: int | Literal['a', 't', 'm', 's', 'b', 'd']
- Vertical alignment of the text. Can be top, bottom or center, a Pillow textanchor (shorthand and longhand), a pssm dimensional string or an integer.Optional, defaults to
"center"
- property background_color: str | int | list | tuple[L, A] | tuple[R, G, B] | tuple[R, G, B, A] | None
Optional, defaults to
None
- property font_color: str | int | list | tuple[L, A] | tuple[R, G, B] | tuple[R, G, B, A]
Optional, defaults to
"black"
- property outline_color: str | int | list | tuple[L, A] | tuple[R, G, B] | tuple[R, G, B, A] | None
Optional, defaults to
None
- property hold_action: str | Callable[[Element, InteractEvent, Any], Any] | None
Optional, defaults to
None
- property hold_release_action: str | Callable[[Element, InteractEvent, Any], Any] | None
Optional, defaults to
None
- property tap_action: str | Callable[[Element, InteractEvent, Any], Any] | None
Optional, defaults to
None
- property feedback_duration: duration
Optional, defaults to
0.75
- property fit_text: bool
Optional, defaults to
False
- property font
Optional, defaults to
"default"
- property font_size: str | int | float
Optional, defaults to
"H*0.036"
- property margins: tuple[int, int, int, int]
Optional, defaults to
0
- property multiline: bool
Optional, defaults to
False
- property outline_width: str | int | float
Optional, defaults to
1
- property radius: str | int | float
Optional, defaults to
0
- property resize: bool | str | int | float
Optional, defaults to
False
- property text: str
Optional, defaults to
""
- property text_anchor_alignment: tuple[Literal[None, 'l', 'm', 'r', 's'], Literal[None, 'a', 't', 'm', 's', 'b', 'd']]
Optional, defaults to
(None, None)
- property text_x_position: int | Literal['l', 'm', 'r', 's']
Optional, defaults to
"center"
- property text_y_position: int | Literal['a', 't', 'm', 's', 'b', 'd']
Optional, defaults to
"center"
background_color, Optional, defaults toNone. Color of the element background.font_color, Optional, defaults to"black". The color of the fontoutline_color, Optional, defaults toNone. Color of the elements outline.hold_action, Optional, defaults toNone. The function called when the element is held.hold_release_action, Optional, defaults toNone. The function called when the element is released from being held down.tap_action, Optional, defaults toNone. The function called when the element is tapped.feedback_duration, Optional, defaults to0.75. Duration of the element’s feedback functionfit_text, Optional, defaults toFalse. Adjusts the font size automatically to make it fit.font, Optional, defaults to"default". The path to the element’s font.font_size, Optional, defaults to"H*0.036". The size of the fontmargins, Optional, defaults to0. The text margins.multiline, Optional, defaults toFalse. Allows the button to try and fit its text over multiple lines.outline_width, Optional, defaults to1. The width of the outline of the background rectangleradius, Optional, defaults to0. Corner radius of the encapsulating rectangle.resize, Optional, defaults toFalse. Tracks thefont_sizeand adjusts it to fit. Theresizevalue updates and will be used as a starting point for the next update.text, Optional, defaults to"". The current text displayed on the button.text_anchor_alignment, Optional, defaults to(None, None). Alignment of the textAnchor as (horizontal,vertical).text_x_position, Optional, defaults to"center". Horizontal alignment of the text.text_y_position, Optional, defaults to"center". Vertical alignment of the text.