.. include:: headings.inc .. _SpinCtrl: ========================================================================================================================================== |phoenix_title| **SpinCtrl** ========================================================================================================================================== :ref:`SpinCtrl` combines :ref:`TextCtrl` and :ref:`SpinButton` in one control. .. _SpinCtrl-styles: |styles| Window Styles ================================ This class supports the following styles: - ``SP_ARROW_KEYS``: The user can use arrow keys to change the value. - ``SP_WRAP``: The value wraps at the minimum and maximum. - ``TE_PROCESS_ENTER``: Indicates that the control should generate ``wxEVT_COMMAND_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. - ``ALIGN_LEFT``: Same as ``TE_LEFT`` for :ref:`TextCtrl`: the text is left aligned. - ``ALIGN_CENTRE``: Same as ``TE_CENTRE`` for :ref:`TextCtrl`: the text is centered. - ``ALIGN_RIGHT``: Same as ``TE_RIGHT`` for :ref:`TextCtrl`: the text is right aligned (this is the default). .. _SpinCtrl-events: |events| Events Emitted by this Class ===================================== Handlers bound for the following event types will receive a :ref:`SpinEvent` parameter. - EVT_SPINCTRL: Process a wxEVT_COMMAND_SPINCTRL_UPDATED event, which is generated whenever the numeric value of the spin control is updated. You may also use the :ref:`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 :ref:`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 :ref:`SpinEvent` sent then if the value is different from the last value sent. .. seealso:: :ref:`SpinButton`, :ref:`SpinCtrlDouble`, :ref:`Control` | |class_hierarchy| Inheritance Diagram ===================================== Inheritance diagram for class **SpinCtrl** .. raw:: html

Inheritance diagram of SpinCtrl

| |appearance| Control Appearance =============================== | .. figure:: _static/images/widgets/fullsize/wxmsw/spinctrl.png :alt: wxMSW :figclass: floatleft **wxMSW** .. figure:: _static/images/widgets/fullsize/wxmac/spinctrl.png :alt: wxMAC :figclass: floatright **wxMAC** .. figure:: _static/images/widgets/fullsize/wxgtk/spinctrl.png :alt: wxGTK :figclass: floatcenter **wxGTK** | |method_summary| Methods Summary ================================ ================================================================================ ================================================================================ :meth:`~SpinCtrl.__init__` Default constructor. :meth:`~SpinCtrl.Create` Creation function called by the spin control constructor. :meth:`~SpinCtrl.GetMax` Gets maximal allowable value. :meth:`~SpinCtrl.GetMin` Gets minimal allowable value. :meth:`~SpinCtrl.GetRange` :meth:`~SpinCtrl.GetValue` Gets the value of the spin control. :meth:`~SpinCtrl.SetMax` :meth:`~SpinCtrl.SetMin` :meth:`~SpinCtrl.SetRange` Sets range of allowable values. :meth:`~SpinCtrl.SetSelection` Select the text in the text part of the control between positions `from` (inclusive) and `to` (exclusive). :meth:`~SpinCtrl.SetValue` Sets the value of the spin control. ================================================================================ ================================================================================ | |property_summary| Properties Summary ===================================== ================================================================================ ================================================================================ :attr:`~SpinCtrl.Max` See :meth:`~SpinCtrl.GetMax` and :meth:`~SpinCtrl.SetMax` :attr:`~SpinCtrl.Min` See :meth:`~SpinCtrl.GetMin` and :meth:`~SpinCtrl.SetMin` :attr:`~SpinCtrl.Range` See :meth:`~SpinCtrl.GetRange` :attr:`~SpinCtrl.Value` See :meth:`~SpinCtrl.GetValue` and :meth:`~SpinCtrl.SetValue` ================================================================================ ================================================================================ | |api| Class API =============== .. class:: SpinCtrl(Control) SpinCtrl combines TextCtrl and SpinButton in one 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") .. method:: __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 :meth:`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. :param `parent`: Parent window. Must not be ``None``. :type `parent`: Window :param `id`: Window identifier. The value ``ID_ANY`` indicates a default value. :type `id`: int :param `value`: Default value (as text). :type `value`: string :param `pos`: Window position. If ``DefaultPosition`` is specified then a default position is chosen. :type `pos`: Point :param `size`: Window size. If ``DefaultSize`` is specified then a default size is chosen. :type `size`: Size :param `style`: Window style. See :ref:`SpinButton`. :type `style`: long :param `min`: Minimal value. :type `min`: int :param `max`: Maximal value. :type `max`: int :param `initial`: Initial value. :type `initial`: int :param `name`: Window name. :type `name`: string .. seealso:: :meth:`Create` **~~~** .. method:: 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 :ref:`SpinCtrl` for details. :param `parent`: :type `parent`: Window :param `id`: :type `id`: int :param `value`: :type `value`: string :param `pos`: :type `pos`: Point :param `size`: :type `size`: Size :param `style`: :type `style`: long :param `min`: :type `min`: int :param `max`: :type `max`: int :param `initial`: :type `initial`: int :param `name`: :type `name`: string :rtype: `bool` .. method:: GetMax(self) Gets maximal allowable value. :rtype: `int` .. method:: GetMin(self) Gets minimal allowable value. :rtype: `int` .. method:: GetRange(self) .. method:: GetValue(self) Gets the value of the spin control. :rtype: `int` .. method:: SetMax(self, maxVal) .. method:: SetMin(self, minVal) .. method:: SetRange(self, minVal, maxVal) Sets range of allowable values. :param `minVal`: :type `minVal`: int :param `maxVal`: :type `maxVal`: int .. method:: 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 :meth:`TextCtrl.SetSelection` . :param `from_`: :type `from_`: long :param `to_`: :type `to_`: long .. note:: this is currently only implemented for Windows and generic versions of the control. .. method:: SetValue(self, *args, **kw) |overload| **Overloaded Implementations**: **~~~** **SetValue** `(self, text)` Sets the value of the spin control. Use the variant using int instead. :param `text`: :type `text`: string **~~~** **SetValue** `(self, value)` Sets the value of the spin control. :param `value`: :type `value`: int **~~~** .. attribute:: Max See :meth:`~SpinCtrl.GetMax` and :meth:`~SpinCtrl.SetMax` .. attribute:: Min See :meth:`~SpinCtrl.GetMin` and :meth:`~SpinCtrl.SetMin` .. attribute:: Range See :meth:`~SpinCtrl.GetRange` .. attribute:: Value See :meth:`~SpinCtrl.GetValue` and :meth:`~SpinCtrl.SetValue`