A collection of things for widgets to use. These can be imported with a from _locals import * line.
get_screen(): Returns the screen object.
Class containing fonts available for use.
Index class to get fonts, such as Font["widget"] for the widget font.
Set fonts to a specific font. If a font exists, it will be replaced, otherwise it will be newly created.
Base widget, all widgets inherit from this.
Attributes to customise widget:
True if the widget can receive focus. The widget will not be able to receive events if it is not focused.
(w,h) A tuple containing the default size of the widget in pixels.
True if the widget should be modal (blocks other widgets from receiving focus). This will normally be used in combination with _layered.
True if the widget should be layered. This means the widget will float above other widgets, such as a dialog window.
Flags to be passed to pygame.surface.Surface when creating the images. This will typically just be SRCALPHA when the widget wants transparency.
This is a tuple containing the names of the different image states for the widget. See the tutorial.
This is a dictionary containing the names and sizes of the extra images for the widget. See the tutorial.
Change this attribute to change the default image state the widget should display. This should not be changed directly after initialisation.
This is a dictionary containing the default settings for the widget. It will be copied to self._settings when the widget is instantiated.
This should be assigned the parent widget, if this widget is attached to another. This is mainly used in container widgets.
Override these methods to customise widget behaviour:
Overload to update the widget per frame.
Overload to process events received by the widget one at a time.
Called when focus should be changed. Used primarily by the Container widget.
Override to provide configuration options. Receives the keyword arguments user passed to self.config(). Will also receive “init” when the widget is instantiated, which can be used to initialise some things (preferred from overriding __init__).
Widgets should overload to draw default images found in self._images. This method will not be called when the user gives a custom image.
Widgets should overload to draw final things that should be drawn regardless of whether a custom image was used or not.
Called when the widget gains focus. Overload to customise behaviour.
Called when the widget loses focus. Overload to customise behaviour.
Useful functions that can be used by the widget:
Creates the base surfaces to draw on, or uses existing images.
If self._default_size is None, widget is expected to call this function manually when no size is given.
Draw a dotted rectangle to show keyboard focus.
Returns a GUI pygame.event.Event object. The first argument must be the value for gui_type and should roughly describe the event. Optional keyword arguments can also be passed with additional attributes for the event.
Switch image state to the given image name.
Given no arguments will simply refresh the current image.
Simple label that can be displayed next to widgets.
This differs from the normal label widget in that it is attached to a widget and should not be used standalone. This is automatically attached by the base widget when the user passes the label argument to config(). Args:
text: Text label should display.parent: Widget label should be attached to.
Colour of label text. Defaults to Font.col. Changed in the base widget when “label_col” is passed to self.config().
Font used for label text. Defaults to Font[“widget”]. Changed in the base widget when “label_font” is passed to self.config().
The text that should be displayed. Changed in the base widget when “label” is passed to self.config().
Return which side widget should be attached to. Returns parent._label_side or defaults to “right”.
Returns the rect aligned to the appropriate side of it’s parent.