| 1 |
.. currentmodule:: gi.repository |
| 2 |
|
| 3 |
SpinButton |
| 4 |
========== |
| 5 |
A :class:`Gtk.SpinButton` is an ideal way to allow the user to set the value of |
| 6 |
some attribute. Rather than having to directly type a number into a |
| 7 |
:class:`Gtk.Entry`, :class:`Gtk.SpinButton` allows the user to click on one of |
| 8 |
two arrows to increment or decrement the displayed value. A value can still be |
| 9 |
typed in, with the bonus that it can be checked to ensure it is in a given range. |
| 10 |
The main properties of a :class:`Gtk.SpinButton` are set through |
| 11 |
:class:`Gtk.Adjustment`. |
| 12 |
|
| 13 |
To change the value that :class:`Gtk.SpinButton` is showing, use |
| 14 |
:attr:`Gtk.SpinButton.props.value`. The value entered can either be an integer |
| 15 |
or float, depending on your requirements, use |
| 16 |
:meth:`Gtk.SpinButton.get_value_as_int` or :meth:`Gtk.SpinButton.get_value`, |
| 17 |
respectively. |
| 18 |
|
| 19 |
When you allow the displaying of float values in the spin button, you may wish |
| 20 |
to adjust the number of decimal spaces displayed by calling |
| 21 |
:attr:`Gtk.SpinButton.props.digits`. |
| 22 |
|
| 23 |
By default, :class:`Gtk.SpinButton` accepts textual data. If you wish to limit |
| 24 |
this to numerical values only, set :attr:`Gtk.SpinButton.props.numeric` to ``True``. |
| 25 |
|
| 26 |
We can also adjust the update policy of :class:`Gtk.SpinButton`. There are two |
| 27 |
options here; by default the spin button updates the value even if the data |
| 28 |
entered is invalid. Alternatively, we can set the policy to only update when the |
| 29 |
value entered is valid by changing :attr:`Gtk.SpinButton.props.update_policy` to |
| 30 |
:attr:`Gtk.SpinButtonUpdatePolicy.IF_VALID`. |
| 31 |
|
| 32 |
Example |
| 33 |
^^^^^^^ |
| 34 |
|
| 35 |
.. image:: images/spinbutton.png |
| 36 |
|
| 37 |
.. literalinclude:: examples/spinbutton.py |
| 38 |
:linenos: |