Skip to content
Download
API reference

SpinBox

Inherits: Range < Control < CanvasItem < Actor < Object

An input field for numbers.

SpinBox is a numerical input text field. It allows entering integers and floating-point numbers. The SpinBox also has up and down buttons that can be clicked to increase or decrease the value. The value can also be changed by dragging the mouse up or down over the SpinBox’s arrows.

Additionally, mathematical expressions can be entered. These are evaluated when the user presses Enter while editing the SpinBox’s text field. This uses the Expression class to parse and evaluate the expression. The result of the expression is then set as the value of the SpinBox. Some examples of valid expressions are 5 + 2 * 3, pow(2, 4), and PI + sin(0.5). Expressions are case-sensitive.

Example: Create a SpinBox, disable its context menu and set its text alignment to right.

spin_box : SpinBox = SpinBox.new()
add_child(spin_box)
line_edit : LineEdit = spin_box.get_line_edit()
line_edit.context_menu_enabled = false
spin_box.alignment = HORIZONTAL_ALIGNMENT_RIGHT

See Range class for more options over the SpinBox.

Note: With the SpinBox’s context menu disabled, you can right-click the bottom half of the spinbox to set the value to its minimum, while right-clicking the top half sets the value to its maximum.

Note: SpinBox relies on an underlying LineEdit actor. To theme a SpinBox’s background, add theme items for LineEdit and customize them. The LineEdit has the SpinBoxInnerLineEdit theme variation, so that you can give it a distinct appearance from regular LineEdits.

Note: If you want to implement drag and drop for the underlying LineEdit, you can use Control.set_drag_forwarding() on the actor returned by get_line_edit().

TypeNameDefault
HorizontalAlignmentalignment0
boolcustom_arrow_roundfalse
floatcustom_arrow_step0.0
booleditabletrue
Stringprefix""
boolselect_all_on_focusfalse
Control.SizeFlagssize_flags_vertical1
floatstep1.0
Stringsuffix""
boolupdate_on_text_changedfalse
ReturnsMethod
voidapply()
LineEditget_line_edit()

HorizontalAlignment alignment = 0

Setter/getter: set_horizontal_alignment(), get_horizontal_alignment()

Changes the alignment of the underlying LineEdit.

bool custom_arrow_round = false

Setter/getter: set_custom_arrow_round(), is_custom_arrow_rounding()

If true, the value will be rounded to a multiple of custom_arrow_step when interacting with the arrow buttons. Otherwise, increments the value by custom_arrow_step and then rounds it according to Range.step.

float custom_arrow_step = 0.0

Setter/getter: set_custom_arrow_step(), get_custom_arrow_step()

If not 0, sets the step when interacting with the arrow buttons of the SpinBox.

Note: Range.value will still be rounded to a multiple of Range.step.

bool editable = true

Setter/getter: set_editable(), is_editable()

If true, the SpinBox will be editable. Otherwise, it will be read only.

String prefix = ""

Setter/getter: set_prefix(), get_prefix()

Adds the specified prefix string before the numerical value of the SpinBox.

bool select_all_on_focus = false

Setter/getter: set_select_all_on_focus(), is_select_all_on_focus()

If true, the SpinBox will select the whole text when the LineEdit gains focus. Clicking the up and down arrows won’t trigger this behavior.

Control.SizeFlags size_flags_vertical = 1

Setter/getter: set_v_size_flags(), get_v_size_flags()

No description yet.

float step = 1.0

Setter/getter: set_step(), get_step()

No description yet.

String suffix = ""

Setter/getter: set_suffix(), get_suffix()

Adds the specified suffix string after the numerical value of the SpinBox.

bool update_on_text_changed = false

Setter/getter: set_update_on_text_changed(), get_update_on_text_changed()

Sets the value of the Range for this SpinBox when the LineEdit text is changed instead of submitted. See LineEdit.text_changed and LineEdit.text_submitted.

Note: If set to true, this will interfere with entering mathematical expressions in the SpinBox. The SpinBox will try to evaluate the expression as you type, which means symbols like a trailing + are removed immediately by the expression being evaluated.

void apply()

Applies the current value of this SpinBox. This is equivalent to pressing Enter while editing the LineEdit used by the SpinBox. This will cause LineEdit.text_submitted to be emitted and its currently contained expression to be evaluated.

LineEdit get_line_edit()

Returns the LineEdit instance from this SpinBox. You can use it to access properties and methods of LineEdit.

Warning: This is a required internal actor, removing and freeing it may cause a crash. If you wish to hide it or any of its children, use their CanvasItem.visible property.