gale.ui.button module

This file contains the implementation of the class Button: a clickable, labeled rectangle, activated by a mouse click or by on_confirm while focused.

Author: Alejandro Mujica (aledrums@gmail.com)

class gale.ui.button.Button(x, y, width, height, text, on_click=None, font=None, theme=None)[source]

Bases: Widget

A clickable rectangle with a centered label. Fires on_click both when clicked with the mouse and when it is the focused widget and on_confirm is triggered (typically bound to Enter/a controller’s “confirm” button through gale.input_handler).

Usage example:

def start_game():

button = Button(220, 200, 200, 48, “Start”, on_click=start_game)

Parameters:
  • x (float)

  • y (float)

  • width (float)

  • height (float)

  • text (str)

  • on_click (Callable[[], None] | None)

  • font (Font | None)

  • theme (Theme | None)

render(surface)[source]
Parameters:

surface (Surface)

Return type:

None

on_mouse_click(position, data)[source]
Parameters:
Return type:

bool

on_confirm()[source]
Return type:

bool