CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-guizero

Python module to allow learners to easily create GUIs

Pending
Overview
Eval results
Files

application.mddocs/

Application Management

Core functionality for creating and managing application windows, including the main application window and secondary windows.

Capabilities

Main Application Window

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): ...

Usage Example

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()

Secondary Windows

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."""

Usage Example

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()

Application Lifecycle

The typical guizero application lifecycle:

  1. Create App: Initialize the main application window
  2. Add Widgets: Create and add widgets to the app or containers
  3. Set Event Handlers: Configure callbacks for user interactions
  4. Display: Call app.display() to start the event loop
  5. Handle Events: Application responds to user interactions
  6. Cleanup: Application closes when user closes window or calls destroy()

Scheduling and Timers

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

docs

application.md

containers.md

dialogs.md

display-widgets.md

index.md

input-widgets.md

menus.md

tile.json