Button

class src.button.ButtonHex(x_y_pos, radius, color, is_filled=True)[source]

A class for creating and drawing hexagonal buttons.

Parameters:
  • x_y_pos (tuple) – A tuple of the x and y coordinates of the center of the button.

  • radius (int) – The radius of the button.

  • color (tuple) – The color of the button.

  • is_filled (bool) – Whether or not the button should be filled in. Defaults to True.

draw(surface)[source]

Draws the hexagonal button onto the specified pygame surface.

Parameters:

surface (pygame.Surface) – The pygame surface to draw the button onto.

is_clicked(mouse_pos)[source]

Returns True if the button is currently being clicked, False otherwise.

Parameters:

mouse_pos (tuple) – The current x and y position of the mouse.

Returns:

Whether or not the button is currently being clicked.

Return type:

bool

is_hovered_over(mouse_pos)[source]

Returns True if the mouse is currently hovering over the button, False otherwise.

Parameters:

mouse_pos (tuple) – The current x and y position of the mouse.

Returns:

Whether or not the mouse is currently hovering over the button.

Return type:

bool

class src.button.ButtonRect(x_y_pos, width_height, text, colors)[source]

A class representing a rectangular button.

Parameters:

x_y_pos – A tuple representing the x and y

coordinates of the top-left corner of the button. :type x_y_pos: Tuple[int, int] :param width_height: A tuple representing the width and height of the button. :type width_height: Tuple[int, int] :param text: The text displayed on the button. :type text: str :param colors: A tuple containing the colors of the button and its highlight when hovered over. :type colors: Tuple[Tuple[int, int, int], Tuple[int, int, int]]

draw(surface)[source]

Draw the button onto the specified surface.

Parameters:

surface (pygame.Surface) – The surface to draw the button onto.

is_clicked(mouse_pos)[source]

Check if the button was clicked.

Parameters:

mouse_pos (Tuple[int, int]) – The current mouse position.

Returns:

True if the button was clicked, False otherwise.

Return type:

bool

is_hovered_over(mouse_pos)[source]

Check if the mouse is currently hovering over the button.

Parameters:

mouse_pos (Tuple[int, int]) – The current mouse position.

Returns:

True if the mouse is hovering over the button, False otherwise.

Return type:

bool