Phoenix Logo

phoenix_title wx.SpinCtrl

wx.SpinCtrl combines wx.TextCtrl and wx.SpinButton in one control.

styles Window Styles

This class supports the following styles:

  • wx.SP_ARROW_KEYS: The user can use arrow keys to change the value.
  • wx.SP_WRAP: The value wraps at the minimum and maximum.
  • wx.TE_PROCESS_ENTER: Indicates that the control should generate wxEVT_TEXT_ENTER events. Using this style will prevent the user from using the Enter key for dialog navigation (e.g. activating the default button in the dialog) under MSW.
  • wx.ALIGN_LEFT: Same as wx.TE_LEFT for wx.TextCtrl: the text is left aligned.
  • wx.ALIGN_CENTRE_HORIZONTAL: Same as wx.TE_CENTRE for wx.TextCtrl: the text is centered.
  • wx.ALIGN_RIGHT: Same as wx.TE_RIGHT for wx.TextCtrl: the text is right aligned (this is the default).

events Events Emitted by this Class

Handlers bound for the following event types will receive a wx.SpinEvent parameter.

  • EVT_SPINCTRL: Process a wxEVT_SPINCTRL event, which is generated whenever the numeric value of the spin control is updated.

You may also use the wx.SpinButton event macros, however the corresponding events will not be generated under all platforms. Finally, if the user modifies the text in the edit part of the spin control directly, the EVT_TEXT is generated, like for the wx.TextCtrl. When the use enters text into the text area, the text is not validated until the control loses focus (e.g. by using the TAB key). The value is then adjusted to the range and a wx.SpinEvent sent then if the value is different from the last value sent.


class_hierarchy Class Hierarchy

Inheritance diagram for class SpinCtrl:

appearance Control Appearance


wxMSW

wxMSW

wxMAC

wxMAC

wxGTK

wxGTK


method_summary Methods Summary

__init__ Default constructor.
Create Creation function called by the spin control constructor.
GetBase Returns the numerical base being currently used, 10 by default.
GetMax Gets maximal allowable value.
GetMin Gets minimal allowable value.
GetRange  
GetValue Gets the value of the spin control.
SetBase Sets the base to use for the numbers in this control.
SetMax  
SetMin  
SetRange Sets range of allowable values.
SetSelection Select the text in the text part of the control between positions from (inclusive) and to (exclusive).
SetValue Sets the value of the spin control.

property_summary Properties Summary

Base See GetBase and SetBase
Max See GetMax and SetMax
Min See GetMin and SetMin
Range See GetRange
Value See GetValue and SetValue

api Class API



class wx.SpinCtrl(Control)

Possible constructors:

SpinCtrl()

SpinCtrl(parent, id=ID_ANY, value="", pos=DefaultPosition,
         size=DefaultSize, style=SP_ARROW_KEYS, min=0, max=100, initial=0,
         name="wxSpinCtrl")

SpinCtrl combines TextCtrl and SpinButton in one control.


Methods



__init__(self, *args, **kw)

overload Overloaded Implementations:



__init__ (self)

Default constructor.



__init__ (self, parent, id=ID_ANY, value=””, pos=DefaultPosition, size=DefaultSize, style=SP_ARROW_KEYS, min=0, max=100, initial=0, name=”wxSpinCtrl”)

Constructor, creating and showing a spin control.

If value is non-empty, it will be shown in the text entry part of the control and if it has numeric value, the initial numeric value of the control, as returned by GetValue will also be determined by it instead of by initial. Hence, it only makes sense to specify initial if value is an empty string or is not convertible to a number, otherwise initial is simply ignored and the number specified by value is used.

Parameters:
  • parent (wx.Window) – Parent window. Must not be None.
  • id (wx.WindowID) – Window identifier. The value wx.ID_ANY indicates a default value.
  • value (string) – Default value (as text).
  • 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.
  • style (long) – Window style. See wx.SpinButton.
  • min (int) – Minimal value.
  • max (int) – Maximal value.
  • initial (int) – Initial value.
  • name (string) – Window name.

See also

Create





Create(self, parent, id=ID_ANY, value="", pos=DefaultPosition, size=DefaultSize, style=SP_ARROW_KEYS, min=0, max=100, initial=0, name="wxSpinCtrl")

Creation function called by the spin control constructor.

See wx.SpinCtrl for details.

Parameters:
  • parent (wx.Window) –
  • id (wx.WindowID) –
  • value (string) –
  • pos (wx.Point) –
  • size (wx.Size) –
  • style (long) –
  • min (int) –
  • max (int) –
  • initial (int) –
  • name (string) –
Return type:

bool



GetBase(self)

Returns the numerical base being currently used, 10 by default.

Return type:int

New in version 2.9.5.

See also

SetBase



GetMax(self)

Gets maximal allowable value.

Return type:int


GetMin(self)

Gets minimal allowable value.

Return type:int


GetRange(self)


GetValue(self)

Gets the value of the spin control.

Return type:int


SetBase(self, base)

Sets the base to use for the numbers in this control.

Currently the only supported values are 10 (which is the default) and 16.

Changing the base allows the user to enter the numbers in the specified base, e.g. with “0x” prefix for hexadecimal numbers, and also displays the numbers in the specified base when they are changed using the spin control arrows.

Parameters:base (int) – Numeric base, currently only 10 and 16 are supported.
Return type:bool
Returns:True if the base was successfully changed or False if it failed, usually meaning that either the base is not 10 or 16.

New in version 2.9.5.



SetMax(self, maxVal)


SetMin(self, minVal)


SetRange(self, minVal, maxVal)

Sets range of allowable values.

Notice that calling this method may change the value of the control if it’s not inside the new valid range, e.g. it will become minVal if it is less than it now. However no wxEVT_SPINCTRL event is generated, even if it the value does change.

Parameters:
  • minVal (int) –
  • maxVal (int) –


SetSelection(self, from_, to_)

Select the text in the text part of the control between positions from (inclusive) and to (exclusive).

This is similar to wx.TextCtrl.SetSelection .

Parameters:
  • from_ (long) –
  • to_ (long) –

Note

this is currently only implemented for Windows and generic versions of the control.



SetValue(self, *args, **kw)

overload Overloaded Implementations:



SetValue (self, text)

Sets the value of the spin control.

It is recommended to use the overload taking an integer value instead.

Notice that, unlike wx.TextCtrl.SetValue , but like most of the other setter methods in wxWidgets, calling this method does not generate any events as events are only generated for the user actions.

Parameters:text (string) –



SetValue (self, value)

Sets the value of the spin control.

Calling this method doesn’t generate any wxEVT_SPINCTRL events.

Parameters:value (int) –




Properties



Base

See GetBase and SetBase



Max

See GetMax and SetMax



Min

See GetMin and SetMin



Range

See GetRange



Value

See GetValue and SetValue