Python module to allow learners to easily create GUIs
—
Core functionality for creating and managing application windows, including the main application window and secondary windows.
The App class creates the main application window that serves as the root container for all GUI elements. It handles the application lifecycle and provides the main event loop.
class App:
def __init__(self, title="guizero", width=500, height=500, layout="auto",
bg=None, visible=True):
"""
Create the main application window.
Args:
title (str): Window title text
width (int): Window width in pixels
height (int): Window height in pixels
layout (str): Layout manager ("auto" or "grid")
bg (str): Background color
visible (bool): Initial visibility state
"""
def display(self):
"""Start the GUI event loop - call this to show the app and begin event handling."""
def destroy(self):
"""Close the application and cleanup resources."""
def exit_full_screen(self):
"""Exit full screen mode."""
def full_screen(self):
"""Enter full screen mode."""
def hide(self):
"""Hide the application window."""
def show(self):
"""Show the application window."""
def cancel(self, callback):
"""Cancel a scheduled callback."""
def repeat(self, time, callback, args=None):
"""
Schedule a callback to repeat at regular intervals.
Args:
time (int): Interval in milliseconds
callback (function): Function to call
args (list): Arguments to pass to callback
"""
def after(self, time, callback, args=None):
"""
Schedule a callback to run once after a delay.
Args:
time (int): Delay in milliseconds
callback (function): Function to call
args (list): Arguments to pass to callback
"""
# Properties
@property
def title(self) -> str:
"""Get/set the window title."""
@title.setter
def title(self, value: str): ...
@property
def width(self) -> int:
"""Get/set the window width."""
@width.setter
def width(self, value: int): ...
@property
def height(self) -> int:
"""Get/set the window height."""
@height.setter
def height(self, value: int): ...
@property
def bg(self) -> str:
"""Get/set the background color."""
@bg.setter
def bg(self, value: str): ...
@property
def full_screen(self) -> bool:
"""Get/set full screen mode."""
@full_screen.setter
def full_screen(self, value: bool): ...
@property
def visible(self) -> bool:
"""Get/set window visibility."""
@visible.setter
def visible(self, value: bool): ...
@property
def tk(self):
"""Access to underlying Tkinter root object."""
# Event handlers
@property
def when_closed(self):
"""Callback function when window is closed."""
@when_closed.setter
def when_closed(self, callback): ...from guizero import App, Text, PushButton
# Create the main application
app = App(title="My Application", width=400, height=300, bg="lightblue")
# Add some widgets
Text(app, text="Welcome to my app!")
def close_app():
app.destroy()
PushButton(app, text="Close", command=close_app)
# Set up event handlers
def on_app_closing():
print("Application is closing")
app.when_closed = on_app_closing
# Start the application
app.display()The Window class creates additional windows that can be opened from the main application. These are useful for dialogs, settings screens, or any secondary interface.
class Window:
def __init__(self, master, title="guizero", width=500, height=500,
layout="auto", bg=None, visible=True):
"""
Create a secondary window.
Args:
master (App): Parent application
title (str): Window title text
width (int): Window width in pixels
height (int): Window height in pixels
layout (str): Layout manager ("auto" or "grid")
bg (str): Background color
visible (bool): Initial visibility state
"""
def show(self):
"""Show the window."""
def hide(self):
"""Hide the window."""
def destroy(self):
"""Close the window and cleanup resources."""
def full_screen(self):
"""Enter full screen mode."""
def exit_full_screen(self):
"""Exit full screen mode."""
# Properties (same as App)
@property
def title(self) -> str:
"""Get/set the window title."""
@title.setter
def title(self, value: str): ...
@property
def width(self) -> int:
"""Get/set the window width."""
@width.setter
def width(self, value: int): ...
@property
def height(self) -> int:
"""Get/set the window height."""
@height.setter
def height(self, value: int): ...
@property
def bg(self) -> str:
"""Get/set the background color."""
@bg.setter
def bg(self, value: str): ...
@property
def visible(self) -> bool:
"""Get/set window visibility."""
@visible.setter
def visible(self, value: bool): ...
@property
def tk(self):
"""Access to underlying Tkinter Toplevel object."""from guizero import App, Window, Text, PushButton
app = App(title="Main Window")
def open_settings():
settings_window = Window(app, title="Settings", width=300, height=200)
Text(settings_window, text="Settings go here")
def close_settings():
settings_window.destroy()
PushButton(settings_window, text="Close", command=close_settings)
PushButton(app, text="Open Settings", command=open_settings)
app.display()The typical guizero application lifecycle:
app.display() to start the event loopdestroy()Apps support scheduling callbacks to run at specific times or intervals:
# Run once after 5 seconds
app.after(5000, my_function)
# Run every 2 seconds
app.repeat(2000, update_clock)
# Cancel a scheduled callback
callback_id = app.repeat(1000, periodic_task)
app.cancel(callback_id)Install with Tessl CLI
npx tessl i tessl/pypi-guizero