wx.ScrollBar

Inheritance diagram for wx.ScrollBar:



Description

A wx.ScrollBar is a control that represents a horizontal or vertical scrollbar. It is distinct from the two scrollbars that some windows provide automatically, but the two types of scrollbar share the way events are received.

Window Styles

Window Style Description
wx.SB_HORIZONTAL Specifies a horizontal scrollbar.
wx.SB_VERTICAL Specifies a vertical scrollbar.

Event Handling

To process a scroll event, use these event handler macros to direct input to member functions that take a wx.ScrollEvent argument. You can use EVT_COMMAND_SCROLL... macros with window IDs for when intercepting scroll events from controls, or EVT_SCROLL... macros without window IDs for intercepting scroll events from the receiving window – except for this, the macros behave exactly the same.

Event Name Description
wx.EVT_SCROLL(func) Process all scroll events.
wx.EVT_SCROLL_TOP(func) Process wx.wxEVT_SCROLL_TOP scroll-to-top events (minimum position).
wx.EVT_SCROLL_BOTTOM(func) Process wx.wxEVT_SCROLL_BOTTOM scroll-to-bottom events (maximum position).
wx.EVT_SCROLL_LINEUP(func) Process wx.wxEVT_SCROLL_LINEUP line up events.
wx.EVT_SCROLL_LINEDOWN(func) Process wx.wxEVT_SCROLL_LINEDOWN line down events.
wx.EVT_SCROLL_PAGEUP(func) Process wx.wxEVT_SCROLL_PAGEUP page up events.
wx.EVT_SCROLL_PAGEDOWN(func) Process wx.wxEVT_SCROLL_PAGEDOWN page down events.
wx.EVT_SCROLL_THUMBTRACK(func) Process wx.wxEVT_SCROLL_THUMBTRACK thumbtrack events (frequent events sent as the user drags the thumbtrack).
wx.EVT_SCROLL_THUMBRELEASE(func) Process wx.wxEVT_SCROLL_THUMBRELEASE thumb release events.
wx.EVT_SCROLL_CHANGED(func) Process wx.wxEVT_SCROLL_CHANGED end of scrolling events (MSW only).
wx.EVT_COMMAND_SCROLL(id, func) Process all scroll events.
wx.EVT_COMMAND_SCROLL_TOP(id, func) Process wx.wxEVT_SCROLL_TOP scroll-to-top events (minimum position).
wx.EVT_COMMAND_SCROLL_BOTTOM(id, func) Process wx.wxEVT_SCROLL_BOTTOM scroll-to-bottom events (maximum position).
wx.EVT_COMMAND_SCROLL_LINEUP(id, func) Process wx.wxEVT_SCROLL_LINEUP line up events.
wx.EVT_COMMAND_SCROLL_LINEDOWN(id, func) Process wx.wxEVT_SCROLL_LINEDOWN line down events.
wx.EVT_COMMAND_SCROLL_PAGEUP(id, func) Process wx.wxEVT_SCROLL_PAGEUP page up events.
wx.EVT_COMMAND_SCROLL_PAGEDOWN(id, func) Process wx.wxEVT_SCROLL_PAGEDOWN page down events.
wx.EVT_COMMAND_SCROLL_THUMBTRACK(id, func) Process wx.wxEVT_SCROLL_THUMBTRACK thumbtrack events (frequent events sent as the user drags the thumbtrack).
wx.EVT_COMMAND_SCROLL_THUMBRELEASE(func) Process wx.wxEVT_SCROLL_THUMBRELEASE thumb release events.
wx.EVT_COMMAND_SCROLL_CHANGED(func) Process wx.wxEVT_SCROLL_CHANGED end of scrolling events (MSW only).

Remarks

A scrollbar has the following main attributes: range, thumb size, page size, and position.

The range is the total number of units associated with the view represented by the scrollbar. For a table with 15 columns, the range would be 15.

The thumb size is the number of units that are currently visible. For the table example, the window might be sized so that only 5 columns are currently visible, in which case the application would set the thumb size to 5. When the thumb size becomes the same as or greater than the range, the scrollbar will be automatically hidden on most platforms.

The page size is the number of units that the scrollbar should scroll by, when ‘paging’ through the data. This value is normally the same as the thumb size length, because it is natural to assume that the visible window size defines a page.

The scrollbar position is the current thumb position.

Most applications will find it convenient to provide a function called AdjustScrollbars which can be called initially, from an OnSize event handler, and whenever the application data changes in size. It will adjust the view, object and page size according to the size of the window and the size of the data.


Control Appearance


wxMSW

wxMSW

wxMAC

wxMAC

wxGTK

wxGTK


Class API

Methods

__init__(parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.SB_HORIZONTAL, validator=wx.DefaultValidator, name=wx.ScrollBarNameStr)

Constructor, creating and showing a scrollbar.

Parameters:


Returns:

wx.ScrollBar


GetPageSize()

Returns the page size of the scrollbar.

This is the number of scroll units that will be scrolled when the user pages up or down. Often it is the same as the thumb size.


Returns:

int

See also

SetScrollbar


GetRange()

Returns the length of the scrollbar.


Returns:

int

See also

SetScrollbar


GetThumbPosition()

Returns the current position of the scrollbar thumb.


Returns:

int

See also

SetThumbPosition


GetThumbSize()

Returns the thumb or ‘view’ size.


Returns:

int

See also

SetScrollbar


IsVertical()
No docstrings available for this method.

SetScrollbar(position, thumbSize, range, pageSize, refresh=True)

Sets the scrollbar properties.

Let’s say you wish to display 50 lines of text, using the same font. The window is sized so that you can only see 16 lines at a time.

You would use:

scrollbar.SetScrollbar(0, 16, 50, 15)

The page size is 1 less than the thumb size so that the last line of the previous page will be visible on the next page, to help orient the user.

Note

Note that with the window at this size, the thumb position can never go above 50 minus 16, or 34.

Parameters:

  • position (int): The position of the scrollbar in scroll units.
  • thumbSize (int): The size of the thumb, or visible portion of the scrollbar, in scroll units.
  • range (int): The maximum position of the scrollbar.
  • pageSize (int): The size of the page size in scroll units. This is the number of units the scrollbar will scroll when it is paged up or down. Often it is the same as the thumb size.
  • refresh (bool): True to redraw the scrollbar, False otherwise.

Note

You can determine how many lines are currently visible by dividing the current view size by the character height in pixels.

Note

When defining your own scrollbar behaviour, you will always need to recalculate the scrollbar settings when the window size changes. You could therefore put your scrollbar calculations and SetScrollbar call into a function named AdjustScrollbars, which can be called initially and also from a wx.SizeEvent event handler function.


SetThumbPosition(viewStart)

Sets the position of the scrollbar.

Parameters:

  • viewStart (int): The position of the scrollbar thumb.

See also

GetThumbPosition


Properties

PageSize
See GetPageSize
Range
See GetRange
ThumbPosition
See GetThumbPosition and SetThumbPosition
ThumbSize
See GetThumbSize