ScrollBar

class pygame_menu.widgets.ScrollBar(length, values_range, scrollbar_id='', orientation='__pygame_menu_orientation_horizontal__', slider_pad=0, slider_color=(200, 200, 200), page_ctrl_thick=20, page_ctrl_color=(235, 235, 235), onchange=None, onreturn=None, *args, **kwargs)[source]

Bases: pygame_menu.widgets.core.widget.Widget

A scroll bar include 3 separate controls: a slider, scroll arrows, and a page control:

  1. The slider provides a way to quickly go to any part of the document
  2. The scroll arrows are push buttons which can be used to accurately navigate to a particular place in a document.
  3. The page control is the area over which the slider is dragged (the scroll bar’s background). Clicking here moves the scroll bar towards the click by one “page”.

Warning

Arrows are not yet implemented

Parameters:
  • length (int) – Length of the page control
  • values_range (tuple, list) – Min and max values
  • scrollbar_id (str) – Bar identifier
  • orientation (str) – Bar orientation ORIENTATION_HORIZONTAL/ORIENTATION_VERTICAL
  • slider_pad (int, float) – Space between slider and page control
  • slider_color (tuple, list) – Color of the slider
  • page_ctrl_thick (int, float) – Page control thickness
  • page_ctrl_color (tuple, list) – Page control color
  • onchange (callable, None) – Callback when changing the selector
  • onreturn (callable, None) – Callback when pressing return button
apply(*args)

Run on_return callback when return event. A callback function receives the following arguments:

callback_func( value, *args, *widget._args, **widget._kwargs )
with:
  • value (if something is returned by get_value())
  • args given to this method
  • args of the widget
  • kwargs of the widget
Parameters:
  • args – Extra arguments passed to the callback
  • args – any
Returns:

None

change(*args)

Run on_change callback after change event is triggered. A callback function receives the following arguments:

callback_func( value, *args, *widget._args, **widget._kwargs )
with:
  • value (if something is returned by get_value())
  • args given to this method
  • args of the widget
  • kwargs of the widget
Parameters:
  • args – Extra arguments passed to the callback
  • args – any
Returns:

None

draw(surface)[source]

Draw the widget shape.

Parameters:surface (pygame.Surface) – Surface to draw
Returns:None
draw_selection(surface)

Draw selection effect on widget.

Parameters:surface (pygame.Surface) – Surface to draw
Returns:None
get_alignment()

Return the widget alignment.

Returns:Widget align, see locals
Return type:str
get_attribute(key, default)

Get attribute value.

Parameters:
  • key (str) – Key of the attribute
  • default (any) – Value if does not exists
Returns:

Attribute data

Return type:

any

get_font_info()

Return a dict with the information of the widget font.

Returns:Dict, keys: size (int), name (str), color (tuple), selected_color (tuple), antialias (bool)
Return type:dict
get_id()

Return the widget ID.

Returns:Widget ID
Return type:str
get_margin()

Return the widget margin.

Returns:Widget margin
Return type:tuple
get_maximum()[source]

Return the greatest acceptable value.

Returns:Greatest acceptable value
Return type:int
get_menu()

Return the menu reference (if exists).

Returns:Menu reference
Return type:pygame_menu.Menu, None
get_minimum()[source]

Return the smallest acceptable value.

Returns:Smallest acceptable value
Return type:int
get_orientation()[source]

Return the scrollbar orientation (pygame-menu locals).

Returns:Scrollbar orientation
Return type:str
get_page_step()[source]

Return amount that the value changes by when the user click on the page control surface.

Returns:Page step
Return type:int
get_rect()

Return the Rect object, this forces the widget rendering.

Returns:Widget rect
Return type:pygame.Rect
get_selected_time()

Return time the widget has been selected in miliseconds. If the widget is not currently selected, return 0.

Returns:Time in ms
Return type:float
get_selection_effect()

Return the selection effect.

Returns:Selection effect
Return type:pygame_menu.widgets.core.Selection
get_title()

Return the widget title.

Returns:Widget title
Return type:str
get_value()[source]

Return the value according to the slider position.

Returns:Position in pixels
Return type:int
set_alignment(align)

Set the alignment of the widget.

Parameters:align (str) – Widget align, see locals
Returns:None
set_attribute(key, value)

Set widget attribute.

Parameters:
  • key (str) – Key of the attribute
  • value (any) – Value of the attribute
Returns:

None

set_background_color(color, inflate=(0, 0))

Set widget background color.

Parameters:
Returns:

None

set_controls(joystick=True, mouse=True, touchscreen=True)

Enable interfaces to control the widget.

Parameters:
  • joystick (bool) – Use joystick
  • mouse (bool) – Use mouse
  • touchscreen (bool) – Use touchscreen
Returns:

None

set_font(font, font_size, color, selected_color, background_color, antialias=True)

Set the text font.

Parameters:
  • font (str, list) – Name or list of names for font (see pygame.font.match_font for precise format)
  • font_size (int) – Size of font in pixels
  • color (tuple) – Text color
  • selected_color (tuple) – Text color when widget is selected
  • background_color (tuple) – Font background color
  • antialias (bool) – Determines if antialias is applied to font (uses more processing power)
Returns:

None

set_length(value)[source]

Set the length of the page control area.

Parameters:value (int, float) – Length of the area
Returns:None
set_margin(x, y)

Set Widget margin.

Parameters:
Returns:

None

set_max_width(width)

Set widget max width (column support) if force_fit_text is enabled.

Parameters:width (int, float, None) – Width in px, None if max width is disabled
Returns:None
set_maximum(value)[source]

Set the greatest acceptable value.

Parameters:value (int, float) – Maximum value
Returns:None
set_menu(menu)

Set the menu reference.

Parameters:menu (pygame_menu.Menu) – Menu object
Returns:None
set_minimum(value)[source]

Set the smallest acceptable value.

Parameters:value (int, float) – Minimum value
Returns:None
set_orientation(orientation)[source]

Set the scroll bar orientation to vertical or horizontal.

Parameters:orientation (str) – Widget orientation, could be ORIENTATION_HORIZONTAL / ORIENTATION_VERTICAL
Returns:None
set_page_step(value)[source]

Set the amount that the value changes by when the user click on the page control surface. The length of the slider is related to this value, and typically represents the proportion of the document area shown in a scrolling view.

Parameters:value (int, float) – Page step
Returns:None
set_position(posx, posy)

Set the position.

Parameters:
Returns:

None

set_selected(selected=True)

Mark the widget as selected.

Parameters:selected (bool) – Set item as selected
Returns:None
set_selection_effect(selection)

Set the selection effect handler.

Parameters:selection (pygame_menu.widgets.core.Selection) – Selection effect class
Returns:None
set_shadow(enabled=True, color=None, position=None, offset=None)

Show text shadow.

Parameters:
  • enabled (bool) – Shadow is enabled or not
  • color (list, None) – Shadow color
  • position (str, None) – Shadow position
  • offset (int, float, None) – Shadow offset
Returns:

None

set_sound(sound)

Set sound engine to the widget.

Parameters:sound (pygame_menu.sound.Sound) – Sound object
Returns:None
set_title(title)

Update the widget title.

Parameters:title (str) – New title
Returns:None
set_value(value)[source]

Set the position of the scrollbar.

Parameters:value (int, float) – Position
Returns:None
surface_needs_update()

Checks if the widget width/height has changed because events. If so, return true and set the status of the widget (menu widget position needs update) as false. This method is used by .update() from Menu class.

Returns:True if the widget position has changed by events after the rendering.
Return type:bool
update(events)[source]

Update internal variable according to the given events list and fire the callbacks.

Parameters:events (list[pygame.event.Event]) – List of pygame events
Returns:True if updated
Return type:bool