GUI#

arcade.gui.UIMessageBox#

class arcade.gui.UIMessageBox(*, width: float, height: float, message_text: str, buttons=('Ok',))[source]#

A simple dialog box that pops up a message with buttons to close. Subclass this class or overwrite the ‘on_action’ event handler with

box = UIMessageBox(...)
@box.event("on_action")
def on_action(event: UIOnActionEvent):
    pass
Parameters:
  • width – Width of the message box

  • height – Height of the message box

  • message_text – Text to show as message to the user

  • buttons – List of strings, which are shown as buttons

on_action(event: UIOnActionEvent)[source]#

Called when button was pressed

arcade.gui.UIDraggableMixin#

class arcade.gui.UIDraggableMixin(x: float = 0, y: float = 0, width: float = 100, height: float = 100, children: Iterable[UIWidget] = (), size_hint=None, size_hint_min=None, size_hint_max=None, style=None, **kwargs)[source]#

UIDraggableMixin can be used to make any UIWidget draggable.

Example, create a draggable Frame, with a background, useful for window like constructs:

class DraggablePane(UITexturePane, UIDraggableMixin):

This does overwrite UILayout behaviour which position themselves, like UIAnchorWidget

arcade.gui.UIMouseFilterMixin#

class arcade.gui.UIMouseFilterMixin(x: float = 0, y: float = 0, width: float = 100, height: float = 100, children: Iterable[UIWidget] = (), size_hint=None, size_hint_min=None, size_hint_max=None, style=None, **kwargs)[source]#

UIMouseFilterMixin can be used to catch all mouse events which occur inside this widget.

Useful for window like widgets, UIMouseEvents should not trigger effects which are under the widget.

arcade.gui.UIWindowLikeMixin#

class arcade.gui.UIWindowLikeMixin(x: float = 0, y: float = 0, width: float = 100, height: float = 100, children: Iterable[UIWidget] = (), size_hint=None, size_hint_min=None, size_hint_max=None, style=None, **kwargs)[source]#

Makes a widget window like:

  • handles all mouse events that occur within the widgets boundaries

  • can be dragged

arcade.gui.Surface#

class arcade.gui.Surface(*, size: Tuple[int, int], position: Tuple[int, int] = (0, 0), pixel_ratio: float = 1.0)[source]#

Holds a arcade.gl.Framebuffer and abstracts the drawing on it. Used internally for rendering widgets.

activate()[source]#

Save and restore projection and activate Surface buffer to draw on. Also resets the limit of the surface (viewport).

clear(color: Union[Tuple[int, int, int], List[int], Tuple[int, int, int, int]] = (0, 0, 0, 0))[source]#

Clear the surface

draw() None[source]#

Draws the current buffer on screen

draw_sprite(x, y, width, height, sprite)[source]#

Draw a sprite to the surface

limit(x, y, width, height)[source]#

Reduces the draw area to the given rect

property position: Tuple[int, int]#

Get or set the surface position

resize(*, size: Tuple[int, int], pixel_ratio: float) None[source]#

Resize the internal texture by re-allocating a new one

Parameters:
  • size (Tuple[int,int]) – The new size in pixels (xy)

  • pixel_ratio (float) – The pixel scale of the window

property size#

Size of the surface in window coordinates

property size_scaled#

The physical size of the buffer

arcade.gui.UIManager#

class arcade.gui.UIManager(window: Optional[Window] = None)[source]#

UIManager is the central component within Arcade’s GUI system. Handles window events, layout process and rendering.

To process window events, UIManager.enable() has to be called, which will inject event callbacks for all window events and redirects them through the widget tree.

If used within a view UIManager.enable() should be called from View.on_show_view() and UIManager.disable() should be called from View.on_hide_view()

Supports size_hint to grow/shrink direct children dependent on window size. Supports size_hint_min to ensure size of direct children (e.g. UIBoxLayout). Supports size_hint_max to ensure size of direct children (e.g. UIBoxLayout).

manager = UIManager()
manager.enable() # hook up window events

manager.add(Dummy())

def on_draw():
    self.clear()

    ...

    manager.draw() # draws the UI on screen
add(widget: W, *, index=None) W[source]#

Add a widget to the UIManager. Added widgets will receive ui events and be rendered.

By default the latest added widget will receive ui events first and will be rendered on top of others.

Parameters:
  • widget – widget to add

  • index – position a widget is added, None has the highest priority

Returns:

the widget

adjust_mouse_coordinates(x, y)[source]#

This method is used, to translate mouse coordinates to coordinates respecting the viewport and projection of cameras. The implementation should work in most common cases.

If you use scrolling in the arcade.Camera you have to reset scrolling or overwrite this method using the camera conversion:

ui_manager.adjust_mouse_coordinates = camera.mouse_coordinates_to_world
clear()[source]#

Remove all widgets from UIManager

debug()[source]#

Walks through all widgets of a UIManager and prints out the rect

disable()[source]#

Remove handler functions (on_…) from arcade.Window

If every arcade.View uses its own arcade.gui.UIManager, this method should be called in arcade.View.on_hide_view().

enable()[source]#

Registers handler functions (on_…) to arcade.gui.UIElement

on_draw is not registered, to provide full control about draw order, so it has to be called by the devs themselves.

get_widgets_at(pos, cls=<class 'arcade.gui.widgets.UIWidget'>) Iterable[W][source]#

Yields all widgets containing a position, returns first top laying widgets which is instance of cls.

Parameters:
  • pos – Pos within the widget bounds

  • cls – class which the widget should be instance of

Returns:

iterator of widgets of given type at position

remove(child: UIWidget)[source]#

Removes the given widget from UIManager.

Parameters:

child (UIWidget) – widget to remove

trigger_render()[source]#

Request rendering of all widgets

walk_widgets(*, root: Optional[UIWidget] = None) Iterable[UIWidget][source]#

walks through widget tree, in reverse draw order (most top drawn widget first)