Button

Pyglet-gui ships a standard button and two variations of it. A Button is a mixing of:

because it is a controllable viewer with two states (“is pressed” and “is not pressed”).

class pyglet_gui.buttons.Button

A TwoStateController and Viewer represented as a label and texture drawn on top of each other.

Parameters:
  • label – The string written in the button.
  • is_pressed – True if the button starts pressed
  • on_press – A callback function of one argument called when the button is pressed (optional).

Attributes:

label

The label of the button (a string).

Accepted events:

on_mouse_press()

Switches the state of the button.

[button, down], [button, up]:

default path in the theme.

class pyglet_gui.buttons.OneTimeButton

A Button that changes back to its original state when the mouse is released.

Parameters:
  • label – The string written in the button.
  • on_release – A callback function of one argument called when the button is released (optional).

Accepted events:

on_mouse_release()

Switches the state back and calls the callback if the mouse was released inside the button.

[button, down], [button, up]

default path in the theme.

class pyglet_gui.buttons.Checkbox
A button drawn as a checkbox icon with the label on the side.
Parameters:
  • label – A string written in the button graphics.
  • is_pressed – True if the button starts pressed
  • on_press – A callback function of one argument called when the button is pressed (optional).
  • align – Whether the label is left or right of the checkbox.
  • padding – The distance from the label to the checkbox.
['checkbox', 'checked'], ['checkbox', 'unchecked']

default path in the theme.

class pyglet_gui.buttons.FocusButton

A Button that is focusable and thus can be selected with TAB.

Parameters:
  • label – The string written in the button.
  • is_pressed – True if the button starts pressed
  • on_press – A callback function of one argument called when the button is pressed (optional).

Accepted events:

on_mouse_press()

Switches the state of the button.

on_key_press()

If the Button have focus and ENTER is pressed the state of the button is switched.

[button, down], [button, up]

default path in the theme.