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).
- __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,
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.
- 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.
- 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,
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(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:
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,
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:
- 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.