wx.Slider¶A slider is a control with a handle which can be pulled back and forth to change the value.
On Windows, the track bar control is used.
On GTK+, tick marks are only available for version 2.16 and later.
Slider generates the same events as wx.ScrollBar but in practice the most convenient way to process wx.Slider updates is by handling the slider-specific wxEVT_SLIDER event which carries wx.CommandEvent containing just the latest slider position.
^^
Window Styles¶This class supports the following styles:
wx.SL_HORIZONTAL: Displays the slider horizontally (this is the default).
wx.SL_VERTICAL: Displays the slider vertically.
wx.SL_AUTOTICKS: Displays tick marks (Windows, GTK+ 2.16 and later).
wx.SL_MIN_MAX_LABELS: Displays minimum, maximum labels (new since wxWidgets 2.9.1).
wx.SL_VALUE_LABEL: Displays value label (new since wxWidgets 2.9.1).
wx.SL_LABELS: Displays minimum, maximum and value labels (same as wx.SL_VALUE_LABEL and wx.SL_MIN_MAX_LABELS together).
wx.SL_LEFT: Displays ticks on the left and forces the slider to be vertical (Windows and GTK+ 3 only).
wx.SL_RIGHT: Displays ticks on the right and forces the slider to be vertical.
wx.SL_TOP: Displays ticks on the top (Windows and GTK+ 3 only).
wx.SL_BOTTOM: Displays ticks on the bottom (this is the default).
wx.SL_BOTH: Displays ticks on both sides of the slider. Windows only.
wx.SL_SELRANGE: Displays a highlighted selection range. Windows only.
wx.SL_INVERSE: Inverses the minimum and maximum endpoints on the slider. Not compatible with wx.SL_SELRANGE. ^^
SL_LEFT , SL_TOP , SL_RIGHT and SL_BOTTOM specify the position of the slider ticks and that the slider labels, if any, are positioned on the opposite side. So, to have a label on the left side of a vertical slider, wx.SL_RIGHT must be used (or none of these styles at all should be specified as left and top are default positions for the vertical and horizontal sliders respectively).
^^
Events Emitted by this Class¶Handlers bound for the following event types will receive a wx.ScrollEvent parameter.
EVT_SCROLL: Process all scroll events.
EVT_SCROLL_TOP: Process wxEVT_SCROLL_TOP scroll-to-top events (minimum position).
EVT_SCROLL_BOTTOM: Process wxEVT_SCROLL_BOTTOM scroll-to-bottom events (maximum position).
EVT_SCROLL_LINEUP: Process wxEVT_SCROLL_LINEUP line up events.
EVT_SCROLL_LINEDOWN: Process wxEVT_SCROLL_LINEDOWN line down events.
EVT_SCROLL_PAGEUP: Process wxEVT_SCROLL_PAGEUP page up events.
EVT_SCROLL_PAGEDOWN: Process wxEVT_SCROLL_PAGEDOWN page down events.
EVT_SCROLL_THUMBTRACK: Process wxEVT_SCROLL_THUMBTRACK thumbtrack events (frequent events sent as the user drags the thumbtrack).
EVT_SCROLL_THUMBRELEASE: Process wxEVT_SCROLL_THUMBRELEASE thumb release events.
EVT_SCROLL_CHANGED: Process wxEVT_SCROLL_CHANGED end of scrolling events (MSW only).
EVT_COMMAND_SCROLL: Process all scroll events.
EVT_COMMAND_SCROLL_TOP: Process wxEVT_SCROLL_TOP scroll-to-top events (minimum position).
EVT_COMMAND_SCROLL_BOTTOM: Process wxEVT_SCROLL_BOTTOM scroll-to-bottom events (maximum position).
EVT_COMMAND_SCROLL_LINEUP: Process wxEVT_SCROLL_LINEUP line up events.
EVT_COMMAND_SCROLL_LINEDOWN: Process wxEVT_SCROLL_LINEDOWN line down events.
EVT_COMMAND_SCROLL_PAGEUP: Process wxEVT_SCROLL_PAGEUP page up events.
EVT_COMMAND_SCROLL_PAGEDOWN: Process wxEVT_SCROLL_PAGEDOWN page down events.
EVT_COMMAND_SCROLL_THUMBTRACK: Process wxEVT_SCROLL_THUMBTRACK thumbtrack events (frequent events sent as the user drags the thumbtrack).
EVT_COMMAND_SCROLL_THUMBRELEASE: Process wxEVT_SCROLL_THUMBRELEASE thumb release events.
EVT_COMMAND_SCROLL_CHANGED: Process wxEVT_SCROLL_CHANGED end of scrolling events (MSW only).
EVT_SLIDER: Process wxEVT_SLIDER which is generated after any change of wx.Slider position in addition to one of the events above. Notice that the handler of this event receives a wx.CommandEvent as argument and not wx.ScrollEvent, as all the other handlers. ^^
The difference between EVT_SCROLL_THUMBRELEASE and EVT_SCROLL_CHANGED¶The EVT_SCROLL_THUMBRELEASE event is only emitted when actually dragging the thumb using the mouse and releasing it (This EVT_SCROLL_THUMBRELEASE event is also followed by an EVT_SCROLL_CHANGED event). The EVT_SCROLL_CHANGED event also occurs when using the keyboard to change the thumb position, and when clicking next to the thumb (In all these cases the EVT_SCROLL_THUMBRELEASE event does not happen). In short, the EVT_SCROLL_CHANGED event is triggered when scrolling/ moving has finished independently of the way it had started. Please see the Widgets Sample (“Slider” page) to see the difference between EVT_SCROLL_THUMBRELEASE and EVT_SCROLL_CHANGED in action.
Class Hierarchy¶
Inheritance diagram for class Slider:

Control Appearance¶
wxMSW¶
wxMAC¶
wxGTK¶
Methods Summary¶Default constructor. |
|
Clears the selection, for a slider with the |
|
Clears the ticks. |
|
Used for two-step slider construction. |
|
Returns the line size. |
|
Gets the maximum slider value. |
|
Gets the minimum slider value. |
|
Returns the page size. |
|
Returns the selection end point. |
|
Returns the selection start point. |
|
Returns the thumb length. |
|
Returns the tick frequency. |
|
Gets the current slider value. |
|
Sets the line size for the slider. |
|
Sets the maximum slider value. |
|
Sets the minimum slider value. |
|
Sets the page size for the slider. |
|
Sets the minimum and maximum slider values. |
|
Sets the selection. |
|
Sets the slider thumb length. |
|
Sets a tick position. |
|
Sets the tick mark frequency and position. |
|
Sets the slider position. |
Properties Summary¶See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
See |
|
Class API¶wx.Slider(Control)¶Possible constructors:
Slider()
Slider(parent, id=ID_ANY, value=0, minValue=0, maxValue=100,
pos=DefaultPosition, size=DefaultSize, style=SL_HORIZONTAL,
validator=DefaultValidator, name=SliderNameStr)
A slider is a control with a handle which can be pulled back and forth to change the value.
__init__(self, *args, **kw)¶__init__ (self)
Default constructor.
__init__ (self, parent, id=ID_ANY, value=0, minValue=0, maxValue=100, pos=DefaultPosition, size=DefaultSize, style=SL_HORIZONTAL, validator=DefaultValidator, name=SliderNameStr)
Constructor, creating and showing a slider.
parent (wx.Window) – Parent window. Must not be None.
id (wx.WindowID) – Window identifier. The value wx.ID_ANY indicates a default value.
value (int) – Initial position for the slider.
minValue (int) – Minimum slider position.
maxValue (int) – Maximum slider position.
pos (wx.Point) – Window position. If wx.DefaultPosition is specified then a default position is chosen.
size (wx.Size) – Window size. If wx.DefaultSize is specified then a default size is chosen, which is typically appropriate in the transverse slider direction, but is just fixed 100 (DPI-independent) pixels in the primary direction (i.e. vertical for SL_VERTICAL sliders or horizontal for SL_HORIZONTAL ones), so it may be preferable to specify it explicitly. Conversely, when using non-default size, it’s usually best to use -1 for the transverse size component, meaning that the default should be used, as the appropriate value depends on the platform and theme.
style (long) – Window style. See wx.Slider.
validator (wx.Validator) – Window validator.
name (string) – Window name.
ClearSel(self)¶Clears the selection, for a slider with the wx.SL_SELRANGE style.
Availability
Only available for MSW.
ClearTicks(self)¶Clears the ticks.
Availability
Only available for MSW, GTK.
Create(self, parent, id=ID_ANY, value=0, minValue=0, maxValue=100, point=DefaultPosition, size=DefaultSize, style=SL_HORIZONTAL, validator=DefaultValidator, name=SliderNameStr)¶Used for two-step slider construction.
See wx.Slider for further details.
parent (wx.Window) –
id (wx.WindowID) –
value (int) –
minValue (int) –
maxValue (int) –
point (wx.Point) –
size (wx.Size) –
style (long) –
validator (wx.Validator) –
name (string) –
bool
GetClassDefaultAttributes(variant=WINDOW_VARIANT_NORMAL)¶variant (WindowVariant) –
GetLineSize(self)¶Returns the line size.
int
See also
GetMax(self)¶Gets the maximum slider value.
int
GetMin(self)¶Gets the minimum slider value.
int
GetPageSize(self)¶Returns the page size.
int
See also
GetRange(self)¶GetSelEnd(self)¶Returns the selection end point.
int
GetSelStart(self)¶Returns the selection start point.
int
GetThumbLength(self)¶Returns the thumb length.
int
GetTickFreq(self)¶Returns the tick frequency.
int
GetValue(self)¶Gets the current slider value.
int
SetLineSize(self, lineSize)¶Sets the line size for the slider.
lineSize (int) – The number of steps the slider moves when the user moves it up or down a line.
See also
SetMax(self, maxValue)¶Sets the maximum slider value.
maxValue (int) – The new top end of the slider range.
SetMin(self, minValue)¶Sets the minimum slider value.
minValue (int) – The new bottom end of the slider range.
SetPageSize(self, pageSize)¶Sets the page size for the slider.
pageSize (int) – The number of steps the slider moves when the user pages up or down.
See also
SetRange(self, minValue, maxValue)¶Sets the minimum and maximum slider values.
minValue (int) –
maxValue (int) –
SetSelection(self, startPos, endPos)¶Sets the selection.
startPos (int) – The selection start position.
endPos (int) – The selection end position.
MSW port.
SetThumbLength(self, len)¶Sets the slider thumb length.
len (int) – The thumb length.
MSW port.
SetTick(self, tickPos)¶Sets a tick position.
tickPos (int) – The tick position.
MSW, GTK ports.
SetTickFreq(self, freq)¶Sets the tick mark frequency and position.
freq (int) – Frequency. For example, if the frequency is set to two, a tick mark is displayed for every other increment in the slider’s range.
MSW, GTK ports.
SetValue(self, value)¶Sets the slider position.
value (int) – The slider position.
LineSize¶See GetLineSize and SetLineSize
PageSize¶See GetPageSize and SetPageSize
SelStart¶See GetSelStart
ThumbLength¶See GetThumbLength and SetThumbLength
TickFreq¶See GetTickFreq and SetTickFreq