Skip to main content

Textbox

Represents a textbox element with optional label, hint and validation messages.

Examples​

Live demo

Basic textboxes​

import pglet
from pglet import Textbox, Button, Text
with pglet.page("basic-textboxes") as page:
def button_clicked(e):
t.value = f"Textboxes values are: '{tb1.value}', '{tb2.value}', '{tb3.value}', '{tb4.value}', '{tb5.value}'."
page.update()

t = Text()
tb1 = Textbox(label='Standard')
tb2 = Textbox(label='Disabled', disabled=True, value='First name')
tb3 = Textbox(label='Read-only', read_only=True, value='Last name')
tb4 = Textbox(label="With placeholder", placeholder='Please enter text here')
tb5 = Textbox(label='With an icon', icon='Emoji2')
b = Button(text='Submit', on_click=button_clicked)
page.add(tb1, tb2, tb3, tb4, tb5, b, t)

input()

Required textboxes​

import pglet
from pglet import Textbox, Button
with pglet.page("required-textboxes-with-error-messages") as page:
def button_clicked(e):
if tb1.value =='':
tb1.error_message = 'Field is required'
else:
tb1.error_message = ''
if tb2.value =='':
tb2.error_message = 'Field is required'
else:
tb2.error_message = ''
page.update()

b = Button(text='Validate', on_click=button_clicked)
tb1 = Textbox(label='Required:', required=True)
tb2 = Textbox(required=True)

page.add(tb1, tb2, b)
input()

Textbox with change event​

import pglet
from pglet import Text, Textbox

with pglet.page("textbox-with-change-event") as page:

def textbox_changed(e):
t.value = e.control.value
page.update()

t = Text()
tb = Textbox(
label="Textbox with 'change' event:",
on_change=textbox_changed,
)

page.add(tb, t)
input()

Password with reveal button​

import pglet
from pglet import Textbox
with pglet.page("password-with-reveal-button") as page:

page.add(Textbox(label='Password with reveal button', password=True))

Multiline textboxes​

import pglet
from pglet import Textbox
with pglet.page("multiline-textboxes") as page:

page.add(
Textbox(label='standard', multiline=True),
Textbox(label='disabled', multiline=True, disabled=True, value='line1\nline2\nline3\nline4\nline5\n'),
Textbox(label='With auto adjusted height', multiline=True, auto_adjust_height=True))

Underlined and borderless textboxes​

import pglet
from pglet import Textbox
with pglet.page("underlined-and-borderless-textboxes") as page:

page.add(
Textbox(label='Underlined', underlined=True, placeholder='Enter text here'),
Textbox(label='Borderless', borderless=True, placeholder='Enter text here'))

Underlined and borderless textboxes​

import pglet
from pglet import Textbox
with pglet.page("suffix-prefix-textboxes") as page:

page.add(
Textbox(label='With prefix', prefix='https://'),
Textbox(label='With suffix', suffix='.com'),
Textbox(label='With prefix and suffix', prefix='https://', suffix='.com'))

Properties​

NameTypeDefaultDescription
valuestringCurrent value of the textbox.
labelstringLabel to display above the textbox.
placeholderstringThe short hint displayed in the textbox before the user enters a value.
errorMessagestringStatic error message displayed below the textbox.
descriptionstringDescription displayed below the textbox to provide additional details about what text to enter.
prefixstringPrefix displayed before the textbox contents. This is not included in the value.
suffixstringSuffix displayed after the textbox contents. This is not included in the value.
iconstringIcon shown in the textbox.
iconColorstringIcon color.
multilineboolfalseWhether or not the textbox is a multiline text field.
rowsnumber3Initial size in rows of multiline TextBox.
shiftEnterboolfalseBlocks Enter button in multiline TextBox, but pops up the event, so Stack.submit could be triggered. New line could still be entered with Shift+Enter.
resizablebooltrueControls whether multiline TextBox is resizable by the user. Default is true. autoAdjustHeight is still respected even if resizable is false.
requiredboolfalseDisplay textbox as required.
readOnlyboolfalseIf true, the textbox is readonly.
autoAdjustHeightboolfalseFor multiline textboxes, whether or not to auto adjust textbox height.
borderlessboolfalseWhether or not the textbox is borderless.
underlinedboolfalseWhether or not the textbox is underlined.
alignstringleftText alignment within textbox: left or right.
passwordboolfalseWhether the textbox is a masked field for entering password.
focusedboolfalseWhen set to true the focus is set on the control when it's shown on the page or page opened.
onChangeboolfalseWhether change event should be fired while text is typed into the Textbox. This property is used by command-based client libraries only like Bash.

Events​

NameDescription
changeFires when the typed input for the Textbox has changed. For performance optimization this event is disabled unless onChange property set to true.
focusFires when the control has received focus.
blurFires when the control has lost focus.