pyglet.gui

Classes

class WidgetBase

The base of all widgets.

Attributes

x

X coordinate of the widget.

y

Y coordinate of the widget.

width

Width of the widget.

height

Height of the widget.

aabb

Bounding box of the widget.

The “left”, “bottom”, “right”, and “top” coordinates of the widget. This is expressed as (x, y, x + width, y + height).

__init__(x: int, y: int, width: int, height: int) None
__new__(**kwargs)
class PushButton

Bases: WidgetBase

Instance of a push button.

Triggers the event ‘on_press’ when it is clicked by the mouse. Triggers the event ‘on_release’ when the mouse is released.

__init__(
x: int,
y: int,
pressed: AbstractImage,
depressed: AbstractImage,
hover: AbstractImage | None = None,
batch: Batch | None = None,
group: Group | None = None,
) None

Create a push button.

Parameters:
  • x (int) – X coordinate of the push button.

  • y (int) – Y coordinate of the push button.

  • pressed (AbstractImage) – Image to display when the button is pressed.

  • depressed (AbstractImage) – Image to display when the button isn’t pressed.

  • hover (AbstractImage | None) – Image to display when the button is being hovered over.

  • batch (Batch | None) – Optional batch to add the push button to.

  • group (Group | None) – Optional parent group of the push button.

on_mouse_drag(
x: int,
y: int,
dx: int,
dy: int,
buttons: int,
modifiers: int,
) None
Return type:

None

on_mouse_leave(x: int, y: int) None
Return type:

None

on_mouse_motion(x: int, y: int, dx: int, dy: int) None
Return type:

None

on_mouse_press(x: int, y: int, buttons: int, modifiers: int) None
Return type:

None

on_mouse_release(x: int, y: int, buttons: int, modifiers: int) None
Return type:

None

on_press() None

Event: Dispatched when the button is clicked.

Return type:

None

on_release() None

Event: Dispatched when the button is released.

Return type:

None

update_groups(order: int) None
Return type:

None

event_types: list = ['on_press', 'on_release', 'on_toggle']
property value: bool

Query or set the Widget’s value.

This property allows you to set the value of a Widget directly, without any user input. This could be used, for example, to restore Widgets to a previous state, or if some event in your program is meant to naturally change the same value that the Widget controls. Note that events are not dispatched when changing this property directly.

class ToggleButton

Bases: PushButton

Instance of a toggle button.

Triggers the event ‘on_toggle’ when the mouse is pressed or released.

on_mouse_press(x: int, y: int, buttons: int, modifiers: int) None
Return type:

None

on_mouse_release(x: int, y: int, buttons: int, modifiers: int) None
Return type:

None

on_toggle(value: bool) None

Event: returns True or False to indicate the current state.

Return type:

None

class Slider

Bases: WidgetBase

Instance of a slider made of a base and a knob image.

Triggers the event ‘on_change’ when the knob position is changed. The knob position can be changed by dragging with the mouse, or scrolling the mouse wheel.

__init__(
x: int,
y: int,
base: AbstractImage,
knob: AbstractImage,
edge: int = 0,
batch: Batch | None = None,
group: Group | None = None,
) None

Create a slider.

Parameters:
  • x (int) – X coordinate of the slider.

  • y (int) – Y coordinate of the slider.

  • base (AbstractImage) – Image to display as the background to the slider.

  • knob (AbstractImage) – Knob that moves to show the position of the slider.

  • edge (int) – Pixels from the maximum and minimum position of the slider, to the edge of the base image.

  • batch (Batch | None) – Optional batch to add the slider to.

  • group (Group | None) – Optional parent group of the slider.

on_change(value: float) None

Event: Returns the current value when the slider is changed.

Return type:

None

on_mouse_drag(
x: int,
y: int,
dx: int,
dy: int,
buttons: int,
modifiers: int,
) None
Return type:

None

on_mouse_press(x: int, y: int, buttons: int, modifiers: int) None
Return type:

None

on_mouse_release(x: int, y: int, buttons: int, modifiers: int) None
Return type:

None

on_mouse_scroll(x: int, y: int, scroll_x: float, scroll_y: float) None
Return type:

None

update_groups(order: int) None
Return type:

None

event_types: list = ['on_change']
property value: float

Query or set the Widget’s value.

This property allows you to set the value of a Widget directly, without any user input. This could be used, for example, to restore Widgets to a previous state, or if some event in your program is meant to naturally change the same value that the Widget controls. Note that events are not dispatched when changing this property directly.

class TextEntry

Bases: WidgetBase

Instance of a text entry widget. Allows the user to enter and submit text.

Triggers the event ‘on_commit’, when the user hits the Enter or Return key. The current text string is passed along with the event.

__init__(
text: str,
x: int,
y: int,
width: int,
color: tuple[int, int, int, int] = (255, 255, 255, 255),
text_color: tuple[int, int, int, int] = (0, 0, 0, 255),
caret_color: tuple[int, int, int, int] = (0, 0, 0, 255),
batch: Batch | None = None,
group: Group | None = None,
) None

Create a text entry widget.

Parameters:
  • text (str) – Initial text to display.

  • x (int) – X coordinate of the text entry widget.

  • y (int) – Y coordinate of the text entry widget.

  • width (int) – The width of the text entry widget.

  • color (tuple[int, int, int, int]) – The color of the outline box in RGBA format.

  • text_color (tuple[int, int, int, int]) – The color of the text in RGBA format.

  • caret_color (tuple[int, int, int, int]) – The color of the caret (when it is visible) in RGBA or RGB format.

  • batch (Batch | None) – Optional batch to add the text entry widget to.

  • group (Group | None) – Optional parent group of text entry widget.

on_commit(text: str) None

Event: dispatches the current text when commited via Enter/Return key.

Return type:

None

on_mouse_drag(
x: int,
y: int,
dx: int,
dy: int,
buttons: int,
modifiers: int,
) None
Return type:

None

on_mouse_motion(x: int, y: int, dx: int, dy: int) None
Return type:

None

on_mouse_press(x: int, y: int, buttons: int, modifiers: int) None
Return type:

None

on_text(text: str) None
Return type:

None

on_text_motion(motion: int) None
Return type:

None

on_text_motion_select(motion: int) None
Return type:

None

update_groups(order: int) None
Return type:

None

event_types: list = ['on_commit']
property focus: bool
property height: int

Height of the widget.

property value: str

Query or set the Widget’s value.

This property allows you to set the value of a Widget directly, without any user input. This could be used, for example, to restore Widgets to a previous state, or if some event in your program is meant to naturally change the same value that the Widget controls. Note that events are not dispatched when changing this property directly.

property width: int

Width of the widget.