Previous topic

gui.base Api

Next topic

Writing Custom Widgets

gui.widgets Api

Note

This module and its documentation is still a work in progress.

GUI Widgets

class gui.widgets.AdvancedNumberInput(*args, **kwargs)

Bases: gui.widgets.NumberInput

Extra arguments: :type step_size: number :param step_size: Amount to add per pixel on mouse_dragged.

handle_mouse_dragged(abs, rel, buttons)
handle_mouse_stopped_dragging(pos)
class gui.widgets.NumberInput(*args, **kwargs)

Bases: gui.widgets.TextInput

Extra arguments: :type convert_func: function :param convert_func:

Used to convert the string input to a number
Parameters:
  • min_val (number or None) – Minimum value, used for validation.
  • max_val (number or None) – Maximum value, used for validation.
get_number()
get_text()
set_number(number)
set_text(text)
validate()
class gui.widgets.RectWidget(parent, pos, size=(30, 30), anchor='topleft', **kwargs)

Bases: gui.base.Widget

Unvisible Widget to define click areas.

blit(screen)
class gui.widgets.Scrollbar(parent, size, pos=(0, 0), orient='y', **kwargs)

Bases: gui.base.Layer

handle_slider_move(rel, **kwargs)
init_pos()
update_slider_size(**kw)
class gui.widgets.ScrolledLayer(parent, size=None, pos=(0, 0), **kwargs)

Bases: gui.base.Layer

Scrollable Layer. Not yet for productive use!

Use the scroll_size property to set the scrolled area (ie. what you can reach by scrolling)

get_pos(widget)
get_scroll_size()
size of the scrollable area. Should be larger than self.size
get_styles()
init_pos()
Reset all scrolling offsets.
scroll_to_rel_x(p)
Parameter:p (int) – Relative horizontal position, between 0 and 100
scroll_to_rel_y(p)
Parameter:p (int) – Relative vertical position, between 0 and 100
scroll_to_x(new_x)
Parameter:new_x (int) – Absolute horizontal position to scroll to
scroll_to_y(new_x)
Parameter:new_y (int) – Absolute vertical position to scroll to
scroll_x(offset)
Parameter:offset (int) – amount to scroll to the right

Scroll the layer horizontally.

scroll_y(offset)
Parameter:offset (int) – amount to scroll down

Scroll the layer vertically.

set_scroll_size(new)
scroll_size
size of the scrollable area. Should be larger than self.size
class gui.widgets.Slider(parent, size, pos, anchor='topleft', index='end', style={}, **kwargs)

Bases: gui.base.Widget

Parameters:
  • parent (Layer) – Parent widget
  • size (Size) – Size of the widget.
  • pos (Position) – Position of the widget. (Note the anchor attribute, too.)
  • anchor (String) – The point that should be used for positioning. Must be one of the pygame.Rect attributes (topleft, midtop, center, ...)
  • index (int or “end”) – Index that will be used when adding the widget to the parent widget (via Layer.add()). The rearmost position is at index 0, the topmost position at "end" (default).
  • visible (boolean) – Whether the widget should be visible or not. Defaults to True.
  • validate_pos (boolean) – If True, the widget cannot tower above the parent. This will affect moving and resizing of the widget.
  • min_size (Size) – Minimum size for the widget. Defaults to ("1px, "1px").
  • max_size (Size) – Maximum size for the widget. Defaults to ("100%", "100%").
  • style (Style or dict) – Widget specific style attributes. Fallback defaults to the main GUI style.
  • style_class_name (String) – Prefix used by Style when searching for a style attribute. See documentation on Styling.
  • highlight (boolean) – If True, style names will be prefixed with active_ on mouse over or dragging. Defaults to False.
class gui.widgets.Switch(parent, size, pos, states=[, 'on', 'off'], **kwargs)

Bases: gui.base.Widget

get_state()
get_suffix(name)
handle_mouse_down(button, **kwargs)
set_state(state)
class gui.widgets.TabHead(parent, name, **kwargs)

Bases: gui.base.Layer

get_suffix(name)
handle_mouse_down(button, **kw)
handle_text_resized(**kw)
is_active()
class gui.widgets.TabbedLayer(parent, size, pos=(0, 0), **kwargs)

Bases: gui.base.Layer

get_rect(widget)
handle_tab_added(name, **kw)
new_tab(name, index='end', body=None)
Parameter:body (gui.base.Layer) – A Layer to use as body. This allows you to use child classes of Layer, eg. ScrolledLayer
reorder()
set new positions of tabs
set_active_tab(tab_name)
class gui.widgets.Text(parent, size, pos, text, **kwargs)

Bases: gui.base.Widget

In addition to the default Widget parameters and events, this widget provides the following:

Parameters:
  • size (Size or “auto”) – Size of the text. If the renered text is larger than the Widget size, it will be trimmed. If set to "auto", the Widget will be resized whenever a new text is set to fit the new rendered text size.
  • text (String) – The text to show.
  • align (String) – Vertical align of the text. Must be one of right, left or centered, the default.
  • template (string) – Template string to pre- and/or suffix the editable text. Must contain “%s” exactly once.
Events
text_set - the text was changed
blit_widget(styles)
reblit the text
collide_point(point)
Check for collision with any line.
get_styles()
render_line(line, styles)
Parameter:line (String) – One line of text to render.
Return type:pygame.Surface
Returns:The rendered text.

Render a line of text.

class gui.widgets.TextInput(*args, **kwargs)

Bases: gui.widgets.Text

An editable text widget. Extra arguments: :type multiline: boolean :param multiline:

If True (default), newlines are allowed.

Extra events:

pressed_return
User pressed return. (non-multiline only)
get_text()
handle_events(events)
handle_focus_lost(**kwargs)
handle_focused(**kwargs)
set_text(text)
update_widget()
If focused, add a blinking cursor to the text.
validate()
Validate input data and maybe correct it.
class gui.widgets.Window(parent, title, size=None, pos=(0, 0), **kwargs)

Bases: gui.base.Layer

get_rect(widget)