Python module to allow learners to easily create GUIs
—
Input widgets enable user interaction through various interface elements like buttons, text entry, checkboxes, sliders, and selection lists. These widgets form the core interactive elements of GUI applications.
The PushButton widget creates clickable buttons that execute commands when pressed.
class PushButton:
def __init__(self, master, command=None, args=None, text="Button",
image=None, pady=10, padx=10, grid=None, align=None,
icon=None, visible=True, enabled=None, width=None,
height=None):
"""
Create a clickable button widget.
Args:
master: Parent widget (App, Window, or container)
command (function): Function to call when clicked
args (list): Arguments to pass to command function
text (str): Button text
image (str): Path to image file for button
pady (int): Vertical padding in pixels
padx (int): Horizontal padding in pixels
grid (list): Grid position [x, y] for grid layout
align (str): Alignment ("left", "right", "top", "bottom")
icon (str): Path to icon file
visible (bool): Initial visibility state
enabled (bool): Initial enabled state
width (int): Button width in pixels
height (int): Button height in pixels
"""
def toggle(self):
"""Toggle button state (for toggle buttons)."""
@property
def text(self) -> str:
"""Get/set the button text."""
@text.setter
def text(self, value: str): ...
@property
def image(self) -> str:
"""Get/set the button image."""
@image.setter
def image(self, value: str): ...
@property
def icon(self) -> str:
"""Get/set the button icon."""
@icon.setter
def icon(self, value: str): ...
# Event handlers
@property
def when_clicked(self):
"""Callback function when button is clicked."""
@when_clicked.setter
def when_clicked(self, callback): ...
@property
def when_left_button_pressed(self):
"""Callback when left mouse button is pressed."""
@when_left_button_pressed.setter
def when_left_button_pressed(self, callback): ...
@property
def when_left_button_released(self):
"""Callback when left mouse button is released."""
@when_left_button_released.setter
def when_left_button_released(self, callback): ...The TextBox widget provides single-line or multi-line text input capabilities.
class TextBox:
def __init__(self, master, text="", width=10, height=1, grid=None,
align=None, visible=True, enabled=None, multiline=False,
scrollbar=False, command=None, hide_text=False):
"""
Create a text input widget.
Args:
master: Parent widget (App, Window, or container)
text (str): Initial text content
width (int): Width in characters
height (int): Height in lines (for multiline)
grid (list): Grid position [x, y] for grid layout
align (str): Alignment ("left", "right", "top", "bottom")
visible (bool): Initial visibility state
enabled (bool): Initial enabled state
multiline (bool): Enable multiple lines
scrollbar (bool): Show scrollbar for multiline
command (function): Callback when text changes
hide_text (bool): Hide text for password entry
"""
def clear(self):
"""Clear all text from the text box."""
def append(self, text):
"""
Append text to the end of the text box.
Args:
text (str): Text to append
"""
def get(self):
"""Get the current text content."""
@property
def value(self) -> str:
"""Get/set the text content."""
@value.setter
def value(self, text: str): ...
@property
def hide_text(self) -> bool:
"""Get/set password mode (hide text with asterisks)."""
@hide_text.setter
def hide_text(self, value: bool): ...
@property
def multiline(self) -> bool:
"""Get/set multiline mode."""
@multiline.setter
def multiline(self, value: bool): ...
# Event handlers
@property
def when_clicked(self):
"""Callback when text box is clicked."""
@when_clicked.setter
def when_clicked(self, callback): ...
@property
def when_key_pressed(self):
"""Callback when a key is pressed."""
@when_key_pressed.setter
def when_key_pressed(self, callback): ...
@property
def when_key_released(self):
"""Callback when a key is released."""
@when_key_released.setter
def when_key_released(self, callback): ...The CheckBox widget provides a boolean checkbox input for yes/no or on/off selections.
class CheckBox:
def __init__(self, master, text="", command=None, grid=None, align=None,
visible=True, enabled=None, width=None, height=None):
"""
Create a checkbox widget.
Args:
master: Parent widget (App, Window, or container)
text (str): Label text next to checkbox
command (function): Callback when state changes
grid (list): Grid position [x, y] for grid layout
align (str): Alignment ("left", "right", "top", "bottom")
visible (bool): Initial visibility state
enabled (bool): Initial enabled state
width (int): Widget width in pixels
height (int): Widget height in pixels
"""
@property
def value(self) -> int:
"""Get/set checkbox state (1 for checked, 0 for unchecked)."""
@value.setter
def value(self, state: int): ...
@property
def text(self) -> str:
"""Get/set the checkbox label text."""
@text.setter
def text(self, value: str): ...
# Event handler
@property
def when_clicked(self):
"""Callback when checkbox is clicked."""
@when_clicked.setter
def when_clicked(self, callback): ...The RadioButton widget creates individual radio buttons. Note: RadioButton is designed for internal use by ButtonGroup and should not typically be instantiated directly unless you provide your own StringVar for coordination.
class RadioButton:
def __init__(self, master, text, value, variable, command=None, grid=None,
align=None, visible=True, enabled=None):
"""
Create a radio button widget (typically used internally by ButtonGroup).
Args:
master: Parent widget (App, Window, or container)
text (str): Label text next to radio button (required)
value: Value associated with this radio button (required)
variable: StringVar object to coordinate with other radio buttons (required)
command (function): Callback when selected
grid (list): Grid position [x, y] for grid layout
align (str): Alignment ("left", "right", "top", "bottom")
visible (bool): Initial visibility state
enabled (bool): Initial enabled state
"""
@property
def value(self):
"""Get/set the radio button value."""
@value.setter
def value(self, val): ...
@property
def text(self) -> str:
"""Get/set the radio button label text."""
@text.setter
def text(self, value: str): ...The Slider widget provides a draggable slider for selecting numeric values within a range.
class Slider:
def __init__(self, master, start=0, end=100, horizontal=True, command=None,
grid=None, align=None, visible=True, enabled=None,
width=None, height=None):
"""
Create a slider widget for numeric input.
Args:
master: Parent widget (App, Window, or container)
start (int): Minimum value
end (int): Maximum value
horizontal (bool): True for horizontal, False for vertical
command (function): Callback when value changes
grid (list): Grid position [x, y] for grid layout
align (str): Alignment ("left", "right", "top", "bottom")
visible (bool): Initial visibility state
enabled (bool): Initial enabled state
width (int): Widget width in pixels
height (int): Widget height in pixels
"""
@property
def value(self) -> int:
"""Get/set the slider value."""
@value.setter
def value(self, val: int): ...
@property
def start(self) -> int:
"""Get/set the minimum value."""
@start.setter
def start(self, val: int): ...
@property
def end(self) -> int:
"""Get/set the maximum value."""
@end.setter
def end(self, val: int): ...The Combo widget creates a dropdown list for selecting from predefined options.
class Combo:
def __init__(self, master, options=[], selected=None, command=None,
grid=None, align=None, visible=True, enabled=None,
width=None, height=None):
"""
Create a dropdown/combobox widget.
Args:
master: Parent widget (App, Window, or container)
options (list): List of available options
selected: Initially selected option
command (function): Callback when selection changes
grid (list): Grid position [x, y] for grid layout
align (str): Alignment ("left", "right", "top", "bottom")
visible (bool): Initial visibility state
enabled (bool): Initial enabled state
width (int): Widget width in pixels
height (int): Widget height in pixels
"""
def append(self, option):
"""
Add an option to the dropdown.
Args:
option: Option to add
"""
def remove(self, option):
"""
Remove an option from the dropdown.
Args:
option: Option to remove
"""
def clear(self):
"""Remove all options from the dropdown."""
def insert(self, index, option):
"""
Insert an option at a specific position.
Args:
index (int): Position to insert at
option: Option to insert
"""
@property
def options(self) -> list:
"""Get/set the list of available options."""
@options.setter
def options(self, option_list: list): ...
@property
def value(self):
"""Get/set the selected option."""
@value.setter
def value(self, option): ...The ListBox widget displays a scrollable list of items that users can select from.
class ListBox:
def __init__(self, master, items=[], selected=None, command=None,
multiselect=False, scrollbar=False, grid=None, align=None,
visible=True, enabled=None, width=None, height=None):
"""
Create a list selection widget.
Args:
master: Parent widget (App, Window, or container)
items (list): List of items to display
selected: Initially selected item(s)
command (function): Callback when selection changes
multiselect (bool): Allow multiple selections
scrollbar (bool): Show scrollbar when needed
grid (list): Grid position [x, y] for grid layout
align (str): Alignment ("left", "right", "top", "bottom")
visible (bool): Initial visibility state
enabled (bool): Initial enabled state
width (int): Widget width in pixels
height (int): Widget height in pixels
"""
def append(self, item):
"""
Add an item to the list.
Args:
item: Item to add
"""
def remove(self, item):
"""
Remove an item from the list.
Args:
item: Item to remove
"""
def clear(self):
"""Remove all items from the list."""
def insert(self, index, item):
"""
Insert an item at a specific position.
Args:
index (int): Position to insert at
item: Item to insert
"""
@property
def items(self) -> list:
"""Get/set the list of items."""
@items.setter
def items(self, item_list: list): ...
@property
def value(self):
"""Get/set the selected item(s)."""
@value.setter
def value(self, item): ...from guizero import App, Text, TextBox, PushButton
app = App()
name_label = Text(app, text="Name:")
name_box = TextBox(app)
email_label = Text(app, text="Email:")
email_box = TextBox(app)
result_text = Text(app)
def validate_form():
if not name_box.value.strip():
result_text.value = "Name is required"
result_text.text_color = "red"
elif "@" not in email_box.value:
result_text.value = "Valid email is required"
result_text.text_color = "red"
else:
result_text.value = "Form is valid!"
result_text.text_color = "green"
submit_button = PushButton(app, text="Submit", command=validate_form)
app.display()from guizero import App, Combo, ListBox, PushButton
app = App()
# Combo box with dynamic options
combo = Combo(app, options=["Option 1", "Option 2"])
def add_option():
new_option = f"Option {len(combo.options) + 1}"
combo.append(new_option)
add_button = PushButton(app, text="Add Option", command=add_option)
app.display()from guizero import App, TextBox, Text
app = App()
text_input = TextBox(app)
status_text = Text(app)
def on_key_press(event_data):
status_text.value = f"Key pressed: {event_data.key}"
def on_text_change():
status_text.value = f"Text length: {len(text_input.value)}"
text_input.when_key_pressed = on_key_press
text_input.when_clicked = on_text_change
app.display()Install with Tessl CLI
npx tessl i tessl/pypi-guizero