Input
widget in Supervisely allows to create input fields for text. It is a useful widget for applications that require users to enter text, such as project name, dataset name or path to folder or archive with data.
The Input
widget also allows you to set default text to be displayed in the input field, set text placeholder, set input field to be readonly
, and set a minimum and maximum length for the input.
Input(
value="",
minlength=0,
maxlength=1000,
placeholder="",
size=None,
readonly=False,
widget_id=None
)
Parameters | Type | Description |
---|---|---|
value |
str |
Binding value |
minlength |
int |
Minimum input text length |
maxlength |
int |
Maximum input text length |
placeholder |
str |
Placeholder of input |
size |
Literal["mini", "small", "large", None] |
Size of input |
readonly |
bool |
Same as readonly in native input |
type |
Literal["text", "password"] |
Same as type in native input |
icon |
Literal["search", "edit"] |
Set an icon to indicate input type |
widget_id |
str |
ID of the widget |
Binding value.
type: str
default value: ""
input = Input(value="Start input value")
Minimum input text length.
type: int
default value: 0
input = Input(minlength=5)
Maximum input text length.
type: int
default value: 1000
input = Input(maxlength=500)
Placeholder of input.
type: str
default value: ""
input = Input(placeholder="Please input")
Size of input.
type: Literal["mini", "small", "large", None]
default value: None
input = Input()
input_mini = Input(size="mini", placeholder="input mini")
input_small = Input(size="small", placeholder="input small")
input_large = Input(size="large", placeholder="input large")
Same as readonly in native input.
type: bool
default value: false
input = Input(readonly=True)
Same as type in native input.
type: Literal["text", "password"]
default value: None
input = Input(type="password")
Set an icon to indicate input type. Set to None
to disable icon.
type: Literal["search", "edit"]
default value: None
input = Input(value="Search", icon="search")
ID of the widget.
type: str
default value: None
Attributes and Methods | Description |
---|---|
is_readonly() |
Return True if input is readonly, else False . |
set_value(value: str) |
Set input value. |
get_value() |
Get input value. |
enable_readonly() |
Enable input`s readonly property. |
disable_readonly() |
Disable input`s readonly property. |
set_icon() |
Set icon type: "edit" or "search". |
@value_changed |
Decorator functions is handled when input value is changed. |
You can find this example in our Github repository:
ui-widgets-demos/input/001_input/src/main.py
import os
from random import choice
import supervisely as sly
from dotenv import load_dotenv
from supervisely.app.widgets import Button, Card, Container, Input
First, we load environment variables with credentials and init API for communicating with Supervisely Instance:
load_dotenv("local.env")
load_dotenv(os.path.expanduser("~/supervisely.env"))
api = sly.Api()
input_text = Input(placeholder="Please input")
button_random_planet = Button(text="Random planet name")
button_clean_input = Button(text="Clean input")
button_set_readonly = Button(text="Set readonly")
buttons_container = Container(
widgets=[
button_random_planet,
button_clean_input,
button_set_readonly,
],
direction="horizontal",
)
Prepare a layout for app using Card
widget with the content
parameter and place widget that we've just created in the Container
widget.
card = Card(
title="Input",
content=Container(widgets=[input_text, buttons_container]),
)
layout = Container(widgets=[card], direction="vertical")
Create an app object with layout parameter.
app = sly.Application(layout=layout)
@button_random_planet.click
def random_planet():
input_text.set_value(
choice(
[
"Mercury",
"Venus",
"Earth",
"Mars",
"Jupiter",
"Saturn",
"Uranus",
"Neptune",
]
)
)
@button_clean_input.click
def random_word():
input_text.set_value("")
@button_set_readonly.click
def set_readonly():
if input_text.is_readonly():
input_text.disable_readonly()
print("Readonly: Disabled")
else:
input_text.enable_readonly()
print("Readonly: Enabled")