`textinput()` creates a single-line text input.
Creates a textinput object.
| Item | Description |
|---|---|
| Syntax | `textinput()` |
| Arguments | none |
| Returns | textinput object |
Example:
input = textinput().text('Part 1');
Properties are read-only. Use methods to change GUI object state.
| Property | Type | Description |
|---|---|---|
| `position_x` | number | Current x position. |
| `position_y` | number | Current y position. |
| `size_width` | number | Current width. |
| `size_height` | number | Current height. |
| `visible` | boolean | Current visible state. |
| `enabled` | boolean | Current enabled state. |
| `text` | string | Current text. |
| `ghost` | string | Placeholder text. |
| `readonly` | boolean | Current read-only state. |
Returns a display string for the object.
| Item | Description |
|---|---|
| Syntax | `value.to_string()` |
| Arguments | none |
| Returns | string |
Example:
text = value.to_string();
`clone()` is not supported for `textinput`.
Most visible GUI controls support these methods.
Sets the component position in pixels.
| Item | Description |
|---|---|
| Syntax | `component.position(x, y)` |
| Arguments | `x`: x position; `y`: y position |
| Returns | component object |
Example:
label().position(20, 10);
Sets the component size in pixels. Width and height are clamped to at least `1`.
Some container objects, such as `panel()` and `group()`, use `size(-1, -1)` as a special fit-parent mode.
| Item | Description |
|---|---|
| Syntax | `component.size(width, height)` |
| Arguments | `width`: width in pixels; `height`: height in pixels |
| Returns | component object |
Example:
textinput().size(220, 26);
Shows or hides the component.
| Item | Description |
|---|---|
| Syntax | `component.visible(enabled)` |
| Arguments | `enabled`: boolean |
| Returns | component object |
Example:
status.visible(false);
Enables or disables user interaction with the component.
| Item | Description |
|---|---|
| Syntax | `component.enabled(enabled)` |
| Arguments | `enabled`: boolean |
| Returns | component object |
Example:
run_button.enabled(false);
Sets current text.
| Item | Description |
|---|---|
| Syntax | `textinput.text(value)` |
| Arguments | `value`: text value |
| Returns | textinput object |
Example:
input = textinput().text('Part 1');
Sets placeholder text shown when the input is empty.
| Item | Description |
|---|---|
| Syntax | `textinput.ghost(value)` |
| Arguments | `value`: placeholder text |
| Returns | textinput object |
Example:
input = textinput().ghost('Name');
Enables or disables read-only mode.
| Item | Description |
|---|---|
| Syntax | `textinput.readonly(enabled)` |
| Arguments | `enabled`: boolean |
| Returns | textinput object |
Example:
input = textinput().readonly(true);
Sets a callback called when text changes.
| Item | Description |
|---|---|
| Syntax | `textinput.on_change(callback)` |
| Arguments | `callback`: callable with one argument, the current text |
| Returns | textinput object |
Example:
function name_changed(text) { print('name: ', text); } input = textinput().on_change(name_changed);
name = textinput().position(20, 30).size(220, 26).ghost('Name'); w = window().title('Text Input').size(280, 120); w.add(label().position(20, 8).size(220, 20).text('Part name')); w.add(name); w.show();
Previous: togglegroup
Next: textedit