pyglet.gui

班级

class WidgetBase

属性

x

小工具的X坐标。

y

小工具的Y坐标。

width

小工具的宽度。

height

小工具的高度。

aabb

小工具的边框。

小部件的“左”、“底部”、“右”和“顶部”坐标。这表示为(x,y,x +宽度,y +高度)。

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

基类:WidgetBase

按钮的实例。

在被鼠标单击时触发事件‘on_Press’。释放鼠标时触发事件‘ON_RELEASE’。

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

创建一个按钮。

参数:
  • x (int) -- 按钮的X坐标。

  • y (int) -- 按钮的Y坐标。

  • pressed (AbstractImage) -- 按下按钮时显示的图像。

  • depressed (AbstractImage) -- 未按下按钮时显示的图像。

  • hover (AbstractImage | None) -- 当按钮悬停在上方时显示的图像。

  • batch (Batch | None) -- 可选批次以添加按钮。

  • group (Group | None) -- 按钮的可选父组。

on_mouse_drag(
x: int,
y: int,
dx: int,
dy: int,
buttons: int,
modifiers: int,
) None
返回类型:

None

on_mouse_motion(x: int, y: int, dx: int, dy: int) None
返回类型:

None

on_mouse_press(x: int, y: int, buttons: int, modifiers: int) None
返回类型:

None

on_mouse_release(x: int, y: int, buttons: int, modifiers: int) None
返回类型:

None

on_press() None

事件:在单击按钮时调度。

返回类型:

None

on_release() None

事件:在释放按钮时调度。

返回类型:

None

update_groups(order: float) None
返回类型:

None

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

查询或设置小组件的值。

此属性允许您直接设置Widget的值,无需任何用户输入。 例如,这可以用于将Widgets恢复到以前的状态,或者如果您的程序中的某个事件旨在自然更改Widgets控制的相同值。 请注意,直接更改此属性时不会调度事件。

class ToggleButton

基类:PushButton

切换按钮的实例。

在按下或释放鼠标时触发事件‘ON_TOGGLE’。

on_mouse_press(x: int, y: int, buttons: int, modifiers: int) None
返回类型:

None

on_mouse_release(x: int, y: int, buttons: int, modifiers: int) None
返回类型:

None

on_toggle(value: bool) None

事件:返回True或False以指示当前状态。

返回类型:

None

class Slider

基类:WidgetBase

由底座和旋钮图像组成的滑块的实例。

当旋钮位置改变时触发事件‘on_Change’。可以通过使用鼠标拖动或滚动鼠标滚轮来更改旋钮位置。

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

创建一个滑动块。

参数:
  • x (int) -- 滑动块的X坐标。

  • y (int) -- 滑动块的Y坐标。

  • base (AbstractImage) -- 显示为滑动块背景的图像。

  • knob (AbstractImage) -- 移动以显示滑动器位置的旋钮。

  • edge (int) -- 从滑动块的最大和最小位置到基本图像边缘的像素。

  • batch (Batch | None) -- 可选择要添加滑动块的批次。

  • group (Group | None) -- 滑动块的可选父组。

on_change(value: float) None

事件:当滑块更改时返回当前值。

返回类型:

None

on_mouse_drag(
x: int,
y: int,
dx: int,
dy: int,
buttons: int,
modifiers: int,
) None
返回类型:

None

on_mouse_press(x: int, y: int, buttons: int, modifiers: int) None
返回类型:

None

on_mouse_release(x: int, y: int, buttons: int, modifiers: int) None
返回类型:

None

on_mouse_scroll(x: int, y: int, scroll_x: float, scroll_y: float) None
返回类型:

None

update_groups(order: float) None
返回类型:

None

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

查询或设置小组件的值。

此属性允许您直接设置Widget的值,无需任何用户输入。 例如,这可以用于将Widgets恢复到以前的状态,或者如果您的程序中的某个事件旨在自然更改Widgets控制的相同值。 请注意,直接更改此属性时不会调度事件。

class TextEntry

基类:WidgetBase

文本输入小工具的实例。允许用户输入和提交文本。

当用户按Enter或Return键时触发事件‘ON_COMMIT’。当前文本字符串与事件一起传递。

__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

创建文本输入小部件。

参数:
  • text (str) -- 要显示的初始文本。

  • x (int) -- 文本输入小部件的X坐标。

  • y (int) -- 文本输入小部件的Y坐标。

  • width (int) -- 文本输入小部件的宽度。

  • color (tuple[int, int, int, int]) -- RGBA格式的大纲框的颜色。

  • text_color (tuple[int, int, int, int]) -- RGBA格式文本的颜色。

  • caret_color (tuple[int, int, int, int]) -- RGBA或RB格式的插入符号(可见时)的颜色。

  • batch (Batch | None) -- 可选批量添加文本输入小部件。

  • group (Group | None) -- 文本输入小部件的可选父组。

on_commit(text: str) None

事件:通过Enter/Return键提交时调度当前文本。

返回类型:

None

on_mouse_drag(
x: int,
y: int,
dx: int,
dy: int,
buttons: int,
modifiers: int,
) None
返回类型:

None

on_mouse_motion(x: int, y: int, dx: int, dy: int) None
返回类型:

None

on_mouse_press(x: int, y: int, buttons: int, modifiers: int) None
返回类型:

None

on_text(text: str) None
返回类型:

None

on_text_motion(motion: int) None
返回类型:

None

on_text_motion_select(motion: int) None
返回类型:

None

update_groups(order: float) None
返回类型:

None

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

小工具的高度。

property value: str

查询或设置小组件的值。

此属性允许您直接设置Widget的值,无需任何用户输入。 例如,这可以用于将Widgets恢复到以前的状态,或者如果您的程序中的某个事件旨在自然更改Widgets控制的相同值。 请注意,直接更改此属性时不会调度事件。

property width: int

小工具的宽度。