adafruit_button

UI Buttons for displayio

  • Author(s): Limor Fried

Implementation Notes

Software and Dependencies:

adafruit_button.button

UI Buttons for displayio

  • Author(s): Limor Fried, Channing Ramos

Implementation Notes

Software and Dependencies:

class adafruit_button.button_base.ButtonBase(*args: Any, **kwargs: Any)

Superclass for creating UI buttons for displayio.

Parameters:
  • x (int) – The x position of the button.

  • y (int) – The y position of the button.

  • width (int) – The width of the button in tiles.

  • height (int) – The height of the button in tiles.

  • name (Optional[str]) – A name, or miscellaneous string that is stored on the button.

  • label (Optional[str]) – The text that appears inside the button.

  • label_font (Optional[FontProtocol]) – The button label font. Defaults to ‘’terminalio.FONT’’

  • label_color (Optional[Union[int, Tuple[int, int, int]]]) – The color of the label text. Defaults to 0x0. Accepts an int or a tuple of 3 integers representing RGB values.

  • selected_label (Optional[Union[int, Tuple[int, int, int]]]) – The color of the label text when the button is selected. Accepts an int or a tuple of 3 integers representing RGB values. Defaults to an inverse of label_color.

  • label_scale (Optional[int]) – The scale factor used for the label. Defaults to 1.

contains(point: tuple[int, int] | List[int] | List[Dict[str, int]]) bool

Used to determine if a point is contained within a button. For example, button.contains(touch) where touch is the touch point on the screen will allow for determining that a button has been touched.

property label: str | None

The text label of the button

property label_color: int

The font color of the button

property name: str

The name of the button

property selected: bool

Returns whether the button is selected.

property selected_label: int

The font color of the button when selected. If no color is specified it defaults to the inverse of the label_color

adafruit_button.button

UI Buttons for displayio

  • Author(s): Limor Fried, Channing Ramos

Implementation Notes

Software and Dependencies:

class adafruit_button.button.Button(*args: Any, **kwargs: Any)

Helper class for creating UI buttons for displayio. Provides the following buttons: RECT: A rectangular button. SHAWDOWRECT adds a drop shadow. ROUNDRECT: A rectangular button with rounded corners. SHADOWROUNDRECT adds a drop shadow.

Parameters:
  • x (int) – The x position of the button.

  • y (int) – The y position of the button.

  • width (int) – The width of the button in pixels.

  • height (int) – The height of the button in pixels.

  • name (Optional[str]) – The name of the button.

  • style – The style of the button. Can be RECT, ROUNDRECT, SHADOWRECT, SHADOWROUNDRECT. Defaults to RECT.

  • fill_color (Optional[Union[int, Tuple[int, int, int]]]) – The color to fill the button. Accepts an int or a tuple of 3 integers representing RGB values. Defaults to 0xFFFFFF.

  • outline_color (Optional[Union[int, Tuple[int, int, int]]]) – The color of the outline of the button. Accepts an int or a tuple of 3 integers representing RGB values. Defaults to 0x0.

  • label (Optional[str]) – The text that appears inside the button.

  • label_font (Optional[FontProtocol]) – The button label font. Defaults to ‘’terminalio.FONT’’

  • label_color (Optional[Union[int, Tuple[int, int, int]]]) – The color of the button label text. Accepts an int or a tuple of 3 integers representing RGB values. Defaults to 0x0.

  • selected_fill (Optional[Union[int, Tuple[int, int, int]]]) – The fill color when the button is selected. Accepts an int or a tuple of 3 integers representing RGB values. Defaults to the inverse of the fill_color.

  • selected_outline (Optional[Union[int, Tuple[int, int, int]]]) – The outline color when the button is selected. Accepts an int or a tuple of 3 integers representing RGB values. Defaults to the inverse of outline_color.

  • selected_label (Optional[Union[int, Tuple[int, int, int]]]) – The label color when the button is selected. Accepts an int or a tuple of 3 integers representing RGB values. Defaults to inverting the label_color.

  • label_scale (Optional[int]) – The scale factor used for the label. Defaults to 1.

property fill_color: int | None

The fill color of the button body

property group: displayio.Group

Return self for compatibility with old API.

property height: int

The height of the button

property outline_color: int | None

The outline color of the button body

resize(new_width: int, new_height: int) None

Resize the button to the new width and height given :param int new_width: The desired width in pixels. :param int new_height: he desired height in pixels.

property selected_fill: int | None

The fill color of the button body when selected

property selected_outline: int | None

The outline color of the button body when selected

property width: int

The width of the button