pyglet.gui
Classes
- class WidgetBase
Bases:
EventDispatcherThe 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).
- __new__(**kwargs)
- class PushButton
Bases:
WidgetBaseInstance 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,
- unpressed: AbstractImage,
- hover: AbstractImage | None = None,
- batch: Batch | None = None,
- group: Group | 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.unpressed (
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_press(widget: PushButton) None
Event: Dispatched when the button is clicked.
- Return type:
- on_release(widget: PushButton) None
Event: Dispatched when the button is released.
- Return type:
- class Frame
Bases:
objectThe base Frame object, implementing a 2D spatial hash.
A Frame provides an efficient way to handle dispatching keyboard and mouse events to Widgets. This is done by implementing a 2D spatial hash. Only Widgets that are in the vicinity of the mouse pointer will be passed Window events, which can greatly improve efficiency when a large quantity of Widgets are in use.
- __init__( ) None
Create an instance of a Frame.
- Parameters:
window (
Window) – The SpatialHash will receive events from this Window. Appropriate events will be passed on to all added Widgets.enable (
bool) – Whether to enable frame.cell_size (
int) – The cell (“bucket”) size for each cell in the hash. Widgets may span multiple cells.order (
int) – Widgets use internal ordered Groups for draw sorting. This is the base value for these Groups.
- add_widget(widget: WidgetBase) None
Add a Widget to the spatial hash.
- Return type:
- on_key_press(symbol: int, modifiers: int) None
Pass the event to any widgets within range of the mouse.
- Return type:
- on_key_release(symbol: int, modifiers: int) None
Pass the event to any widgets within range of the mouse.
- Return type:
- on_mouse_motion(x: int, y: int, dx: int, dy: int) None
Pass the event to any widgets within range of the mouse
- Return type:
- on_mouse_press(x: int, y: int, buttons: int, modifiers: int) None
Pass the event to any widgets within range of the mouse.
- Return type:
- on_mouse_release(x: int, y: int, buttons: int, modifiers: int) None
Pass the event to any widgets that are currently active.
- Return type:
- on_mouse_scroll(x: int, y: int, scroll_x: float, scroll_y: float) None
Pass the event to any widgets within range of the mouse.
- Return type:
- on_text_motion(motion: int) None
Pass the event to any widgets within range of the mouse.
- Return type:
- on_text_motion_select(motion: int) None
Pass the event to any widgets within range of the mouse.
- Return type:
- remove_widget(widget: WidgetBase) None
Remove a Widget from the spatial hash.
- Return type:
- class ToggleButton
Bases:
PushButtonInstance of a toggle button.
Triggers the event ‘on_toggle’ when the mouse is pressed or released.
- on_toggle(widget: ToggleButton, value: bool) None
Event: returns True or False to indicate the current state.
- Return type:
- class Slider
Bases:
WidgetBaseInstance 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,
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.
- on_change(widget: Slider, value: float) None
Event: Returns the current value when the slider is changed.
- Return type:
- 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:
WidgetBaseInstance 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,
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(widget: TextEntry, text: str) None
Event: dispatches the current text when committed via Enter/Return key.
- Return type:
- 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.